Package aQute.lib.memoize
Class CloseableMemoizingSupplier<T extends java.lang.AutoCloseable>
- java.lang.Object
-
- aQute.lib.memoize.CloseableMemoizingSupplier<T>
-
- All Implemented Interfaces:
CloseableMemoize<T>
,Memoize<T>
,java.lang.AutoCloseable
,java.util.function.Supplier<T>
class CloseableMemoizingSupplier<T extends java.lang.AutoCloseable> extends java.lang.Object implements CloseableMemoize<T>
The object can exist in one of three states:- initial which means neither
get
orclose
has been called. From this state, the object can transition directly to either open or closed. - open which means memoized is non-null with the value from the wrapped supplier. From this state, the object can transition to closed.
- closed which means memoized is null and any value it may have held was closed. This is a terminal state.
-
-
Constructor Summary
Constructors Constructor Description CloseableMemoizingSupplier(java.util.function.Supplier<? extends T> supplier)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CloseableMemoize<T>
accept(java.util.function.Consumer<? super T> consumer)
Call the consumer with the value of this memoized supplier.void
close()
T
get()
private T
initial()
boolean
isClosed()
Returns whether this memoizing supplier is closed.T
peek()
Peek the value.private static <T extends java.lang.AutoCloseable>
Tvalue(T value)
-
-
-
Constructor Detail
-
CloseableMemoizingSupplier
CloseableMemoizingSupplier(java.util.function.Supplier<? extends T> supplier)
-
-
Method Detail
-
get
public T get()
- Specified by:
get
in interfacejava.util.function.Supplier<T extends java.lang.AutoCloseable>
-
initial
private T initial()
-
value
private static <T extends java.lang.AutoCloseable> T value(T value)
-
peek
public T peek()
Description copied from interface:Memoize
Peek the value.This method will not result in a call to the source supplier.
-
isClosed
public boolean isClosed()
Description copied from interface:CloseableMemoize
Returns whether this memoizing supplier is closed.- Specified by:
isClosed
in interfaceCloseableMemoize<T extends java.lang.AutoCloseable>
- Returns:
true
If this memoizing supplier is closed; otherwisefalse
.
-
close
public void close() throws java.lang.Exception
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.lang.Exception
-
accept
public CloseableMemoize<T> accept(java.util.function.Consumer<? super T> consumer)
Description copied from interface:CloseableMemoize
Call the consumer with the value of this memoized supplier.This method will block closing this memoized supplier while this method is executing.
-
-