Class ReferenceMemoizingSupplier<T>

  • All Implemented Interfaces:
    Memoize<T>, java.util.function.Supplier<T>

    class ReferenceMemoizingSupplier<T>
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.ref.Reference<? extends T> memoized  
      private java.util.function.Function<? super T,​? extends java.lang.ref.Reference<? extends T>> reference  
      private java.util.function.Supplier<? extends T> supplier  
    • Constructor Summary

      Constructors 
      Constructor Description
      ReferenceMemoizingSupplier​(java.util.function.Supplier<? extends T> supplier, java.util.function.Function<? super T,​? extends java.lang.ref.Reference<? extends T>> reference)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T get()  
      T peek()
      Peek the value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • supplier

        private final java.util.function.Supplier<? extends T> supplier
      • reference

        private final java.util.function.Function<? super T,​? extends java.lang.ref.Reference<? extends T>> reference
      • memoized

        private volatile java.lang.ref.Reference<? extends T> memoized
    • Constructor Detail

      • ReferenceMemoizingSupplier

        ReferenceMemoizingSupplier​(java.util.function.Supplier<? extends T> supplier,
                                   java.util.function.Function<? super T,​? extends java.lang.ref.Reference<? extends T>> reference)
    • Method Detail

      • get

        public T get()
        Specified by:
        get in interface java.util.function.Supplier<T>
      • peek

        public T peek()
        Description copied from interface: Memoize
        Peek the value.

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

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