Class ReferenceMemoizingSupplier<T>

java.lang.Object
aQute.bnd.memoize.ReferenceMemoizingSupplier<T>
All Implemented Interfaces:
Memoize<T>, Supplier<T>

class ReferenceMemoizingSupplier<T> extends Object implements Memoize<T>
The object can exist in one of two states:
  • cleared which means memoized holds a cleared reference. This is the initial state. The object transitions to this state if the garbage collector clears the reference. From this state, the object transitions to valued when @{code get} is called.
  • valued which means memoized holds a reference with a value.
  • Field Details

    • supplier

      private final Supplier<? extends T> supplier
    • reference

      private final Function<? super T,? extends Reference<? extends T>> reference
    • memoized

      private volatile Reference<? extends T> memoized
  • Constructor Details

    • ReferenceMemoizingSupplier

      ReferenceMemoizingSupplier(Supplier<? extends T> supplier, Function<? super T,? extends Reference<? extends T>> reference)
  • Method Details

    • get

      public T get()
      Description copied from interface: Memoize
      Get the memoized value.
      Specified by:
      get in interface Memoize<T>
      Specified by:
      get in interface Supplier<T>
      Returns:
      The memoized value.
    • peek

      public T peek()
      Description copied from interface: Memoize
      Peek the memoized value, if any.

      This method will not result in a call to the source supplier.

      Specified by:
      peek in interface Memoize<T>
      Returns:
      The memoized value if a value is memoized; otherwise null.
    • isPresent

      public boolean isPresent()
      Description copied from interface: Memoize
      If a value is memoized, return true. Otherwise return false.

      This method will not result in a call to the source supplier.

      Specified by:
      isPresent in interface Memoize<T>
      Returns:
      true if a value is memoized; otherwise false.
    • toString

      public String toString()
      Overrides:
      toString in class Object