Package aQute.lib.memoize
Class CloseableMemoizingSupplier<T extends AutoCloseable>
java.lang.Object
aQute.lib.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
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.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCall the consumer with the value of this memoized supplier.void
close()
get()
private T
initial()
boolean
isClosed()
Returns whether this memoizing supplier is closed.peek()
Peek the memoized value, if any.private static <T extends AutoCloseable>
Tvalue
(T value)
-
Field Details
-
supplier
-
lock
-
initial
private volatile boolean initial -
memoized
-
-
Constructor Details
-
CloseableMemoizingSupplier
-
-
Method Details
-
get
- Specified by:
get
in interfaceSupplier<T extends AutoCloseable>
-
initial
-
value
-
peek
Description copied from interface:Memoize
Peek the memoized value, if any.This method will not result in a call to the source supplier.
- Specified by:
peek
in interfaceMemoize<T extends AutoCloseable>
- Returns:
- The value if a value is memoized; otherwise
null
.
-
isClosed
public boolean isClosed()Description copied from interface:CloseableMemoize
Returns whether this memoizing supplier is closed.- Specified by:
isClosed
in interfaceCloseableMemoize<T extends AutoCloseable>
- Returns:
true
If this memoizing supplier is closed; otherwisefalse
.
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
accept
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.
- Specified by:
accept
in interfaceCloseableMemoize<T extends AutoCloseable>
- Specified by:
accept
in interfaceMemoize<T extends AutoCloseable>
- Parameters:
consumer
- The consumer to accept the value of this memoized supplier. Must not benull
.- Returns:
- This memoized supplier.
-