Class LazyValue<T>

java.lang.Object
org.apache.jackrabbit.oak.commons.LazyValue<T>
All Implemented Interfaces:
Supplier<T>

public abstract class LazyValue<T> extends Object implements Supplier<T>
An instances of this class represents a lazy value of type T. LazyValue implements an evaluate by need semantics: createValue() is called exactly once when get() is called for the first time.

LazyValue instances are thread safe.

  • Constructor Details

    • LazyValue

      public LazyValue()
  • Method Details

    • createValue

      protected abstract T createValue()
      Factory method called to create the value on an as need basis.
      Returns:
      a new instance for T.
    • hasValue

      public boolean hasValue()
      Returns:
      true iff get() has been called at least once.
    • get

      public T get()
      Get value. Calls createValue() if called for the first time.
      Specified by:
      get in interface Supplier<T>
      Returns:
      the value