Skip to content

Commit

Permalink
Merge branch 'development' into initial-codefactor-suggested-improvem…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
JarvisCraft committed Dec 9, 2019
2 parents 3d39a30 + eb64462 commit b589983
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# PADLA

###### Plain And Direct Language Additions for Java

[![License](https://img.shields.io/github/license/JarvisCraft/padla)](/LICENSE)
[![CodeFactor](https://www.codefactor.io/repository/github/jarviscraft/padla/badge)](https://www.codefactor.io/repository/github/jarviscraft/padla)

## 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:
- [Lombok](https://github.com/rzwitserloot/lombok) for generating boilerplate stuff
- [Jetbrains Annotations](https://github.com/JetBrains/java-annotations) and []() for documenting code logic
- Runtime:
- [Guava](https://github.com/google/guava) for some general-purpose needs
- [GSON](https://github.com/google/gson) for manipulating JSON
- Testing:
- [Junit5](https://github.com/junit-team/junit5/) with related sub-tools for testing
- [Hamcrest](https://github.com/hamcrest/JavaHamcrest) for more creating more readable tests
- [Mockito](https://github.com/mockito/mockito) for mocking in tests
- Additional (these are not inherited by default and are required only if using specific classes):
- [ASM](https://gitlab.ow2.org/asm/asm) for runtime class generation (if using classes annotated with `BytecodeLibrary(ASM)`)
- [Javassist](https://github.com/jboss-javassist/javassist) for runtime class generation (if using classes annotated with `BytecodeLibrary(JAVASSIST)`)
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static <T> Lazy<T> createThreadSafe(@NonNull final Supplier<T> valueSupplier) {
* @apiNote weak lazy stores the value wrapped in weak reference and so it may be GCed
* and so the new one might be recomputed using the value supplier
*/
static <T> Lazy<T> createWeak(@NonNull final Supplier<T> valueSupplier) {
static <T> Lazy<T> createWeak(@NonNull final Supplier<@NotNull T> valueSupplier) {
return new SimpleWeakLazy<>(valueSupplier);
}

Expand Down Expand Up @@ -104,7 +104,7 @@ class SimpleLazy<T> implements Lazy<T> {
*/
@Nullable Supplier<T> valueSupplier;

protected SimpleLazy(@NonNull final Supplier<T> valueSupplier) {
protected SimpleLazy(@SuppressWarnings("NullableProblems") @NonNull final Supplier<T> valueSupplier) {
this.valueSupplier = valueSupplier;
}

Expand All @@ -115,9 +115,10 @@ protected SimpleLazy(@NonNull final Supplier<T> valueSupplier) {

@Override
public T get() {
val valueSupplier = this.valueSupplier;
if (valueSupplier != null) {
value = valueSupplier.get();
valueSupplier = null;
this.valueSupplier = null;
}

return value;
Expand Down Expand Up @@ -153,17 +154,21 @@ class DoubleCheckedLazy<T> implements Lazy<T> {
*/
volatile T value;

protected DoubleCheckedLazy(@NonNull final Supplier<T> valueSupplier) {
protected DoubleCheckedLazy(@SuppressWarnings("NullableProblems") @NonNull final Supplier<T> valueSupplier) {
mutex = new Object[0];
this.valueSupplier = valueSupplier;
}

@Override
public T get() {
if (valueSupplier != null) synchronized (mutex) {
val valueSupplier = this.valueSupplier;
if (valueSupplier != null) {
value = valueSupplier.get();
valueSupplier = null;
val value = this.value = valueSupplier.get();
this.valueSupplier = null;

// make sure no race is possible in theory
return value;
}
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<!-- Testing -->
<version.junit>5.5.2</version.junit>
<version.junit.platform>1.5.2</version.junit.platform>
<version.mockito>3.1.0</version.mockito>
<version.mockito>3.2.0</version.mockito>
</properties>

<name>PADLA for Java</name>
Expand Down

0 comments on commit b589983

Please sign in to comment.