Class MemoizingSupplier<T>

  • Type Parameters:
    T - The type of the object returned by this supplier.
    All Implemented Interfaces:
    java.util.function.Supplier<T>

    public class MemoizingSupplier<T>
    extends java.lang.Object
    implements java.util.function.Supplier<T>
    Wraps a supplier and memoizes the object returned.
    See Also:
    Supplier
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.function.Supplier<T> create  
      private java.util.function.Supplier<T> delegate  
      private boolean initialized  
      private T value  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private MemoizingSupplier​(java.util.function.Supplier<T> create)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T get()  
      void ifInitialized​(java.util.function.Consumer<T> consumer)
      Execute a method on the object returned from the supplier if the object was already created.
      private T init()  
      private T internalGet()  
      static <T> MemoizingSupplier<T> of​(java.util.function.Supplier<T> supplier)  
      • Methods inherited from class java.lang.Object

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

      • create

        private final java.util.function.Supplier<T> create
      • delegate

        private java.util.function.Supplier<T> delegate
      • initialized

        private volatile boolean initialized
      • value

        private T value
    • Constructor Detail

      • MemoizingSupplier

        private MemoizingSupplier​(java.util.function.Supplier<T> create)
    • Method Detail

      • of

        public static <T> MemoizingSupplier<T> of​(java.util.function.Supplier<T> supplier)
      • get

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

        private T internalGet()
      • ifInitialized

        public void ifInitialized​(java.util.function.Consumer<T> consumer)
        Execute a method on the object returned from the supplier if the object was already created. Skips execution if the underlying object was never created.
        Parameters:
        consumer - A consumer for the object returned by this supplier.
      • init

        private T init()