Package aQute.bnd.memoize
Class CloseableMemoizingSupplier<T extends AutoCloseable>
java.lang.Object
aQute.bnd.memoize.CloseableMemoizingSupplier<T>
- All Implemented Interfaces:
CloseableMemoize<T>,Memoize<T>,AutoCloseable,Supplier<T>
class CloseableMemoizingSupplier<T extends AutoCloseable>
extends Object
implements CloseableMemoize<T>
The object can exist in one of three states:
- initial which means neither
getorclosehas 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interface -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCall the consumer with the value of this memoizing supplier.voidclose()get()Get the memoized AutoCloseable value.If a value is memoized, call the consumer with the value of this memoizing supplier.private Tinitial()booleanisClosed()Returns whether this memoizing supplier is closed.booleanIf a value is memoized, returntrue.peek()Peek the memoized value, if any.toString()private static <T extends AutoCloseable>
Tvalue(T value)
-
Field Details
-
lock
-
initial
private volatile boolean initial -
memoized
-
-
Constructor Details
-
CloseableMemoizingSupplier
-
-
Method Details
-
get
Description copied from interface:CloseableMemoizeGet the memoized AutoCloseable value.- Specified by:
getin interfaceCloseableMemoize<T extends AutoCloseable>- Specified by:
getin interfaceMemoize<T extends AutoCloseable>- Specified by:
getin interfaceSupplier<T extends AutoCloseable>- Returns:
- The memoized AutoCloseable value.
-
initial
-
value
-
peek
Description copied from interface:MemoizePeek the memoized value, if any.This method will not result in a call to the source supplier.
- Specified by:
peekin interfaceMemoize<T extends AutoCloseable>- Returns:
- The memoized value if a value is memoized; otherwise
null.
-
isPresent
public boolean isPresent()Description copied from interface:MemoizeIf a value is memoized, returntrue. Otherwise returnfalse.This method will not result in a call to the source supplier.
- Specified by:
isPresentin interfaceMemoize<T extends AutoCloseable>- Returns:
trueif a value is memoized; otherwisefalse.
-
isClosed
public boolean isClosed()Description copied from interface:CloseableMemoizeReturns whether this memoizing supplier is closed.- Specified by:
isClosedin interfaceCloseableMemoize<T extends AutoCloseable>- Returns:
trueIf this memoizing supplier is closed; otherwisefalse.
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
accept
Description copied from interface:CloseableMemoizeCall the consumer with the value of this memoizing supplier.This method will block closing this memoizing supplier while the consumer is executing.
- Specified by:
acceptin interfaceCloseableMemoize<T extends AutoCloseable>- Specified by:
acceptin interfaceMemoize<T extends AutoCloseable>- Parameters:
consumer- The consumer to accept the value of this memoizing supplier. Must not benull.- Returns:
- This memoizing supplier.
-
ifPresent
Description copied from interface:CloseableMemoizeIf a value is memoized, call the consumer with the value of this memoizing supplier. Otherwise do nothing.This method will block closing this memoizing supplier while the consumer is executing.
- Specified by:
ifPresentin interfaceCloseableMemoize<T extends AutoCloseable>- Specified by:
ifPresentin interfaceMemoize<T extends AutoCloseable>- Parameters:
consumer- The consumer to accept the value of this memoizing supplier if a value is memoized. Must not benullif a value is memoized.- Returns:
- This memoizing supplier.
-
toString
-