Code Monkey home page Code Monkey logo

padla's Introduction

PADLA

Logo

logo

All Contributors

License Build Status CodeFactor

Plain And Direct Language Additions for Java

What is it?

PADLA is a collection of useful general-purpose utilities for Java aimed at fulfilling common needs. It uses functional approach intensively and attempts to follow OOP-approach as right as possible. In addition to common tools, it does also provide more specific ones aimed at maximal productivity.

Dependencies

As its dependencies PADLA uses:

  • Compiletime:
  • Testing:
    • Junit5 with related sub-tools for testing
    • Hamcrest for more creating more readable tests
    • Mockito for mocking in tests
  • Additional (these are not inherited by default and are required only if using specific classes):
    • ASM for runtime class generation (if using classes annotated with @UsesBytecodeModification(CommonBytecodeLibrary.ASM))
    • Javassist for runtime class generation (if using classes annotated with @UsesBytecodeModification(CommonBytecodeLibrary.JAVASSIST))
  • Optional (these are not required at all but allow some extra integrations and optimizations):
    • Caffeine for caching of internal components

Contributors ✨

Thanks goes to these wonderful people (emoji key):


PROgrm_JARvis

πŸ’» πŸ“– πŸ€” 🚧 πŸ“¦ πŸ“† πŸš‡ ⚠️ πŸ‘€

Areg Yazychyan

πŸ€” πŸ‘€ πŸ’Ό πŸ’»

xxDark

πŸ’» πŸ€” πŸ›

Daniil Sudomoin

πŸ’» πŸ€”

Yaroslav Bolyukin

πŸ€” πŸ›‘οΈ πŸ“–

Cheryl

πŸš‡ πŸ‘€

This project follows the all-contributors specification. Contributions of any kind welcome!

padla's People

Contributors

jarviscraft avatar mergify[bot] avatar dependabot[bot] avatar dependabot-preview[bot] avatar allcontributors[bot] avatar cheryl-des avatar slutmaker avatar certainlach avatar irinakt avatar snyk-bot avatar

Stargazers

sync. avatar  avatar Nikolay Veselov avatar Aleksandr Ushakov avatar Maksim Kotelnikov avatar eruk avatar Andrew Belunov avatar Daniil Sudomoin avatar Ilya Andreev avatar Kamilla 'ova avatar Mahmoud Rusty Abdelkader avatar Ivan Vinogradov avatar Konstantin Konovalov avatar  avatar Florian HΓΌbner avatar  avatar Muhtaseem Al Mahmud avatar Shanyu Thibaut Juneja avatar jordin avatar Matt avatar Viktor Chernyaev avatar Vladimir Vishnevskii avatar Yan Kurbatov avatar Julian avatar Mikhail Primakov avatar Danila Suslov avatar  avatar Stanislav Panchenko avatar Konstantin Shandurenko avatar Sergey avatar

Watchers

James Cloos avatar  avatar

padla's Issues

Implement collectors/collector "shortcut methods" missing in JDK

when using stream api, we often need collectors such as:

EnumMap/EnumSet:

  • toEnumMap(Class<E extends Enum, Function<? super T, ? extends E> keyMapper, Function<? super T, ? extends U> valueMapper) + all overloaded variants without valueMapper/KeyMapper
  • toEnumSet(Class<E extends Enum)
    If it's possible, add method variants without Class argument by resolving class instance from first element of stream or returning empty set in case of empty stream.

List:

  • sized toList: toList(int size) == toCollection(() -> new ArrayList<>(size))

Other useful collectors or "shortcuts" are a topic for discussion.

Use generic for `toPrimitiveWrapper`.

Description

Currently this method uses Class<?> which can be enhanced by using generic T parameter, i.e. Class<? super T> on parameter and Class<? extends T> as the returned type.

Double read of volatile field

The valueSupplier and value fields of Lazy.DoubleCheckedLazy are volatile. Volatile reading is much more expensive than plain, so it's better to store local references to values rather than read them again.

if (valueSupplier != null) synchronized (mutex) {


if (valueSupplier != null) synchronized (mutex) {

Placeholders benchmark is broken

Current implementation of Placholders benchmark is implemented in the wrong way:

  • Iterations get benchmarked, although they have nothing to do with logic and there is no need to over-complicate benchmarks
  • Multithreading is enabled which is not needed and causes even more inexact results
  • Ineffective regex pattern (and maybe algorithm) is used
  • States have random part which varies between benchmarks (even data length differs)
  • This benchmark is written by me

Cleanup GitHub workflows

Description

Currently GitHub workflows contain redundant comments (such as on on) and invalid job names (such as Build with Maven when actually testing).

This should be resolved.

Add `@EnumHelpers`

Description

Implement @EnumHelpers annotation and the corresponsing annotation processor to generate boilerplate enum methods.

Problem

While Java's enum is a powerful mechanism for describing varios constructions, it has a number of negative aspects which make it not that helpful.

The biggest problem is static E @NotNull [] values() method which is required to always return a fresh copy of the array due to array mutability although it's usually needed for iteration.

Another serious design problem (especially considering padla's philosophy) is inability to do try-match operation, i.e. to try to find an enum constant by a string name alternatively fallin back to null or default value etc.

This PR addresses this by provifing a @EnumHelpers annotation causing the generation of ES utility class for enum E.

Goals

  • Add @EnumHelper allowing generation of:
    • @NotNull Stream<@NotNull E> stream()
    • @NotNull @Unmodifiable List<@NotNull E> values()
    • @Nullable E match(final @NotNull String name) and similar ones
  • implement annotation-processor to generate the helper class

Example

Given

@EnumHelpers
public enum Foo {
    A, B, C
}

the following should be generated:

@Generated
public final class Foos {

    private static final @NotNull Foo @NotNull [] VALUES_ARRAY
            = Foo.values(); // may be used for faster iterations
    private static final @NotNull List<@NotNull Foo> VALUE_LIST
            = Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));

    private Foos() {
        throw new AssertionError("Foos is an utility class and thus should never be instantiated");
    }

    public static @NotNull Stream<@NotNull Foo> stream() {
        return Arrays.stream(VALUES_ARRAY);
    }

    public static @NotNull @Unmodifiable List<@NotNull Foo> values() {
        return VALUES_LIST;
    }

    public static @Nullable Foo match(final @NotNull String name) {
        if (name == null) throw new NullPointerException("name is null");

        switch (name) {
            case "A": return A;
            case "B": return B;
            case "C": return C;
            default: return null;
        }
    }

    public static Foo match(final @NotNull String name, final Foo defaultValue) {
        if (name == null) throw new NullPointerException("name is null");

        switch (name) {
            case "A": return A;
            case "B": return B;
            case "C": return C;
            default: return defaultValue;
        }
    }

    // note: possibly worth specialized lambda
    public static @Nullable Foo match(final @NotNull String name, final @NotNull Supplier<Foo> defaultValueSupplier) {
        if (name == null) throw new NullPointerException("name is null");
        if (defaultValueSupplier== null) throw new NullPointerException("defaultValueSupplieris null");

        switch (foo) {
            case "A": return A;
            case "B": return B;
            case "C": return C;
            default: return defaultValueSupplier.get();
        }
    }

    // ...
}

Notes

Generated class should net rely on Lombok as it may be not used by annotation users.

Subjects to discuss:

  • Documenting annotation should be generated if possible(?) but it is not clear whether some eaxct one (org.jetbrains) should be used or custom (via an annotation parameter).

Java 9+ features support

Currently, Java (1.)8 is the minimal supported version of padla and there are no plans for changing it.
However, while a lot of new helpful features has come with newer Java versions, padla currently only provides backwards-compatibility for these (such as switching between Unsafe implementations) but does not utilize its new features.
This issue is for tracking of bringing this support to padla. There is no guarantees yet if this will happen, however this is a priority task.

Direct looking up sun.misc.Unsafe

Currently, UnsafeClassDefiner tries to get sun.misc.Unsafe directly, ignoring the version of Java.


This may result in the class not being found, as it has been moved to another package since Java 9. Therefore, another implementation of ClassDefiner will be used.

As a solution, you can just replace Class.forName("sun.misc.Unsafe") with your own UnsafeInternals.UNSAFE_CLASS.

[DepShield] (CVSS 9.8) Vulnerability due to usage of commons-collections:commons-collections:3.2.1

Vulnerabilities

DepShield reports that this application's usage of commons-collections:commons-collections:3.2.1 results in the following vulnerability(s):


Occurrences

commons-collections:commons-collections:3.2.1 is a transitive dependency introduced by the following direct dependency(s):

β€’ org.apache.velocity:velocity:1.7
        └─ commons-collections:commons-collections:3.2.1

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

FutureHelper

Need to create a utility class that allows you to combine futures into one large Consumer and Function. I think this will get rid of callback hell in some places. An example is shown in the screenshot

image

[DepShield] (CVSS 5.9) Vulnerability due to usage of com.google.guava:guava:18.0

Vulnerabilities

DepShield reports that this application's usage of com.google.guava:guava:18.0 results in the following vulnerability(s):

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

Utilize `IntWrapper` and other primitive wrappers from minecraft-utils

This wrappers have nothing specific to do with Minecraft and so can be moved to padla.
Moreover, there are major issues with them (such as wrong access-qualifiers on their methods) so this issue also covers fixing them.
Moreover, wrappers for all primitive types should be created, not only for int.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.