-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ideal
committed
Aug 16, 2018
1 parent
6b4f9dd
commit cd6f5d2
Showing
10 changed files
with
224 additions
and
175 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
ideal-common/src/main/java/ideal/sylph/common/base/Suppliers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package ideal.sylph.common.base; | ||
|
||
import java.io.Serializable; | ||
import java.util.function.Supplier; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class Suppliers | ||
{ | ||
private Suppliers() {} | ||
|
||
public static <T> Supplier<T> memoize(Supplier<T> delegate) | ||
{ | ||
return delegate instanceof Suppliers.MemoizingSupplier ? | ||
delegate : | ||
new Suppliers.MemoizingSupplier<>(requireNonNull(delegate)); | ||
} | ||
|
||
public static <T> Supplier<T> goLazy(Supplier<T> delegate) | ||
{ | ||
return delegate instanceof Suppliers.MemoizingSupplier ? | ||
delegate : | ||
new Suppliers.MemoizingSupplier<>(requireNonNull(delegate)); | ||
} | ||
|
||
static class MemoizingSupplier<T> | ||
implements Supplier<T>, Serializable | ||
{ | ||
private final Supplier<T> delegate; | ||
private transient volatile boolean initialized = false; | ||
private transient T value; | ||
private static final long serialVersionUID = 0L; | ||
|
||
MemoizingSupplier(Supplier<T> delegate) | ||
{ | ||
this.delegate = delegate; | ||
} | ||
|
||
public T get() | ||
{ | ||
if (!this.initialized) { | ||
synchronized (this) { | ||
if (!this.initialized) { | ||
T t = this.delegate.get(); | ||
this.value = t; | ||
this.initialized = true; | ||
return t; | ||
} | ||
} | ||
} | ||
|
||
return this.value; | ||
} | ||
|
||
public String toString() | ||
{ | ||
return "Suppliers.memoize(" + this.delegate + ")"; | ||
} | ||
} | ||
} |
38 changes: 0 additions & 38 deletions
38
sylph-controller/src/main/java/ideal/sylph/controller/SylphServlet.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.