Class LazyReference<T>

java.lang.Object
io.github.cowwoc.pouch10.core.LazyReference<T>
Type Parameters:
T - the type of object being referenced
All Implemented Interfaces:
Reference<T>

public abstract class LazyReference<T> extends Object
A reference that initializes a value on demand.

Instances of LazyFactory are not safe for use by multiple threads. If such synchronization is required then it is recommended that ConcurrentLazyReference be used.

  • Constructor Details

    • LazyReference

      protected LazyReference()
      Creates a new instance.
  • Method Details

    • create

      public static <T> LazyReference<T> create(Supplier<T> supplier)
      Creates a new LazyReference.
      Type Parameters:
      T - the type of value returned by the reference
      Parameters:
      supplier - supplies the reference value
      Returns:
      a new LazyReference
    • createValue

      protected abstract T createValue()
      Creates the value. This method is invoked the first time Reference.getValue() is invoked.
      Returns:
      the value
    • isInitialized

      public boolean isInitialized()
      Description copied from interface: Reference
      Indicates if the value was initialized.

      A value may get initialized immediately after this method returns false but once it returns true it will continue to do so indefinitely.

      Specified by:
      isInitialized in interface Reference<T>
      Returns:
      true if the value was initialized
    • getValue

      public T getValue()
      Description copied from interface: Reference
      Returns the value. Subsequent invocations of this method return the same value.
      Specified by:
      getValue in interface Reference<T>
      Returns:
      an object of type <T>
    • toString

      public String toString()
      Overrides:
      toString in class Object