T
- The parametrized type which type value is supplied.public class SupplierWithMemo<T>
extends java.lang.Object
implements java.util.function.Supplier<T>
Modifier and Type | Field and Description |
---|---|
private boolean |
initialized
Indicates that memo is set
|
private java.util.concurrent.locks.ReentrantLock |
lock
The read and write synchronizer
|
private T |
memo
The cached value
|
private java.util.function.Supplier<T> |
supplier
The original supplier
|
Constructor and Description |
---|
SupplierWithMemo(java.util.function.Supplier<T> supplier)
Constructs a supplier with memorization.
|
Modifier and Type | Method and Description |
---|---|
T |
get()
Caches its value and then returns it.
|
private final java.util.function.Supplier<T> supplier
private T memo
private volatile boolean initialized
private java.util.concurrent.locks.ReentrantLock lock
public SupplierWithMemo(java.util.function.Supplier<T> supplier)
supplier
- The original supplier.