Package org.apache.calcite.util
Class LazyReference<T>
java.lang.Object
org.apache.calcite.util.LazyReference<T>
- Type Parameters:
T
- Element Type
This class can is able to do a lazy initiaization
of an object based on a
Supplier
.
In contrast to Suppliers.memoize
, the supplier is passed
at the later point in time, during the call to getOrCompute
.
This allows the usage in abstract base classes with a supplier
method, implemented in a derived class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetOrCompute
(Supplier<T> supplier) Atomically sets the value tosupplier.get()
if the current value was not set yet.void
reset()
Resets the current value.
-
Constructor Details
-
LazyReference
public LazyReference()
-
-
Method Details
-
getOrCompute
Atomically sets the value tosupplier.get()
if the current value was not set yet.This method is reentrant. Different threads will get the same result.
- Parameters:
supplier
- supplier for the new value- Returns:
- the current value.
-
reset
public void reset()Resets the current value.
-