java.util.function.Supplier decorator that caches a singleton result and
makes it available from get() (nullable) and obtain() (null-safe).
A SingletonSupplier can be constructed via of factory methods
or via constructors that provide a default supplier as a fallback. This is
particularly useful for method reference suppliers, falling back to a default
supplier for a method that returned null and caching the result.
| Modifier and Type | Field and Description |
|---|---|
| private final Supplier | |
| private final Supplier | |
| private volatile T | |
| private final Lock | writeLock
Guards access to write operations on the |
| Access | Constructor and Description |
|---|---|
| public | SingletonSupplier(T
the singleton instance (potentially instance, Supplier<? extends T> null)the default supplier as a fallback defaultSupplier)Build a |
| public | SingletonSupplier(Supplier<? extends T>
the immediate instance supplier instanceSupplier, Supplier<? extends T> the default supplier as a fallback defaultSupplier)Build a |
| private | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public T | Returns: the singleton instance (ornull if none)Implements java. |
| public T | Returns: the singleton instance (nevernull)Obtain the shared singleton instance for this supplier. |
| public static <T> SingletonSupplier | Returns: the singleton supplier (nevernull)the singleton instance (never instance)null)Build a |
| public static <T> SingletonSupplier | |
| public static <T> SingletonSupplier | Returns: the singleton supplier, ornull if the instance was nullthe singleton instance (potentially instance)null)Build a |
| public static <T> SingletonSupplier | Returns: the singleton supplier, ornull if the instance supplier was nullthe instance supplier (potentially supplier)null)Build a |
| defaultSupplier | back to summary |
|---|---|
| private final Supplier<? extends T> defaultSupplier
| |
| instanceSupplier | back to summary |
|---|---|
| private final Supplier<? extends T> instanceSupplier
| |
| singletonInstance | back to summary |
|---|---|
| private volatile T singletonInstance
| |
| writeLock | back to summary |
|---|---|
| private final Lock writeLock Guards access to write operations on the | |
| SingletonSupplier | back to summary |
|---|---|
| public SingletonSupplier(T instance, Supplier<? extends T> defaultSupplier) Build a
| |
| SingletonSupplier | back to summary |
|---|---|
| public SingletonSupplier(Supplier<? extends T> instanceSupplier, Supplier<? extends T> defaultSupplier) Build a | |
| SingletonSupplier | back to summary |
|---|---|
| private SingletonSupplier(Supplier<? extends T> supplier) | |
| SingletonSupplier | back to summary |
|---|---|
| private SingletonSupplier(T singletonInstance) | |
| get | back to summary |
|---|---|
| public T get() Implements java. Get the shared singleton instance for this supplier. | |
| obtain | back to summary |
|---|---|
| public T obtain() Obtain the shared singleton instance for this supplier.
| |
| of | back to summary |
|---|---|
| public static <T> SingletonSupplier Build a
| |
| of | back to summary |
|---|---|
| public static <T> SingletonSupplier Build a
| |
| ofNullable | back to summary |
|---|---|
| public static <T> SingletonSupplier Build a
| |
| ofNullable | back to summary |
|---|---|
| public static <T> SingletonSupplier Build a
| |