Class LazyReference<T>

java.lang.Object
org.apache.calcite.util.LazyReference<T>
Type Parameters:
T - Element Type

public class LazyReference<T> extends Object
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 Details

    • LazyReference

      public LazyReference()
  • Method Details

    • getOrCompute

      public T getOrCompute(Supplier<T> supplier)
      Atomically sets the value to supplier.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.