Class ConcurrentLazyReference<T>

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

public abstract class ConcurrentLazyReference<T> extends Object implements Reference<T>
A thread-safe reference that initializes a value on demand.

The implementation is thread-safe.

  • Constructor Details

    • ConcurrentLazyReference

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

    • create

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

      public boolean isInitialized()
      Returns true if the value was initialized.
      Specified by:
      isInitialized in interface Reference<T>
      Returns:
      true if the value was initialized
    • getValue

      public final 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>
    • createValue

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

      public String toString()
      Overrides:
      toString in class Object