final Lazy<Double> l = Lazy.of(Math::random);
l.isEvaluated(); // = false
l.get(); // = 0.123 (random generated)
l.isEvaluated(); // = true
l.get(); // = 0.123 (memoized)
Example of creating a real lazy value (works only with interfaces):
final CharSequence chars = Lazy.val(() -> "Yay!", CharSequence.class);
| Modifier and Type | Field and Description |
|---|---|
| private final ReentrantLock | |
| private static final long | |
| private transient volatile Supplier | |
| private T |
| Modifier and Type | Method and Description |
|---|---|
| private T | |
| public boolean | equals(Object
An object o)Overrides java. Implements io. Clarifies that values have a proper equals() method implemented. |
| public Option | |
| public T | Returns: the lazy evaluated valueImplements io. Evaluates this lazy value and caches it, when called the first time. |
| public int | hashCode()
Overrides java. Implements io. Clarifies that values have a proper hashCode() method implemented. |
| public boolean | |
| public boolean | isEmpty()
Implements io. Checks, this |
| public boolean | Returns: true, if the value is evaluated, false otherwise.Checks, if this lazy value is evaluated. |
| public boolean | |
| public boolean | isSingleValued()
Implements io. States whether this is a single-valued type. |
| public Iterator | |
| public <U> Lazy | map(Function<? super T, ? extends U>
A mapper mapper)Implements io. Maps the underlying value to a different component type. |
| public static < Component type of the T> LazyLazy. | |
| public static < type of the lazy value T> Lazy | |
| public Lazy | peek(Consumer<? super T>
The action that will be performed on the element(s). action)Implements io. Performs the given |
| public static < Type of the lazy values. T> Lazy | |
| public String | stringPrefix()
Implements io. Returns the name of this Value type, which is used by toString(). |
| public String | toString()
Overrides java. Implements io. Clarifies that values have a proper toString() method implemented. |
| public < Type of transformation result U> U | |
| public static < type of the lazy value T> T | Returns: A new instance of TA supplier supplier, Class<T> An interface type)Creates a real _lazy value_ of type |
| private void | writeObject(ObjectOutputStream
An object serialization stream. s)Ensures that the value is evaluated before serialization. |
| lock | back to summary |
|---|---|
| private final ReentrantLock lock | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| supplier | back to summary |
|---|---|
| private transient volatile Supplier<? extends T> supplier | |
| value | back to summary |
|---|---|
private T value
| |
| Lazy | back to summary |
|---|---|
| private Lazy(Supplier<? extends T> supplier) | |
| computeValue | back to summary |
|---|---|
| private T computeValue() | |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Overrides java. Implements io. Doc from io. Clarifies that values have a proper equals() method implemented. | |
| filter | back to summary |
|---|---|
| public Option | |
| get | back to summary |
|---|---|
| public T get() Implements io. Evaluates this lazy value and caches it, when called the first time. On subsequent calls, returns the cached value.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements io. Doc from io. Clarifies that values have a proper hashCode() method implemented. See Object.hashCode().
| |
| isAsync | back to summary |
|---|---|
| public boolean isAsync() Implements io. A
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements io. Doc from io. Checks, this
| |
| isEvaluated | back to summary |
|---|---|
| public boolean isEvaluated() Checks, if this lazy value is evaluated. Note A value is internally evaluated (once) by calling
| |
| isLazy | back to summary |
|---|---|
| public boolean isLazy() Implements io. A
| |
| isSingleValued | back to summary |
|---|---|
| public boolean isSingleValued() Implements io. Doc from io. States whether this is a single-valued type.
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements io. Doc from io. Returns a rich | |
| map | back to summary |
|---|---|
| public <U> Lazy Implements io. Doc from io. Maps the underlying value to a different component type. | |
| narrow | back to summary |
|---|---|
| public static <T> Lazy Narrows a widened
| |
| of | back to summary |
|---|---|
| public static <T> Lazy Creates a
| |
| peek | back to summary |
|---|---|
| public Lazy Implements io. Doc from io. Performs the given | |
| sequence | back to summary |
|---|---|
| public static <T> Lazy Reduces many
| |
| stringPrefix | back to summary |
|---|---|
| public String stringPrefix() Implements io. Doc from io. Returns the name of this Value type, which is used by toString(). | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Implements io. Doc from io. Clarifies that values have a proper toString() method implemented. See Object.toString(). | |
| transform | back to summary |
|---|---|
| public <U> U transform(Function<? super Lazy<T>, ? extends U> f) Transforms this
| |
| val | back to summary |
|---|---|
| public static <T> T val(Supplier<? extends T> supplier, Class<T> type) Creates a real _lazy value_ of type
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException Ensures that the value is evaluated before serialization.
| |