Interface Lazy<T>

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default T get()
      Returns the value held by this lazy.
      boolean isInitialized()
      Indicates whether this lazy value has been initialized.
      static <T> Lazy<T> lazy​(java.util.function.Supplier<T> supplier)
      Creates a strict lazy value using the provided Supplier.
      default <R> Lazy<R> map​(java.util.function.Function<? super T,​? extends R> function)
      Creates a new lazy value derived from this lazy value using the provided value mapping function.
      static <T> Lazy<T> pure​(java.util.function.Supplier<T> supplier)
      Creates a pure lazy value using the provided Supplier to initialize the value.
      void set​(T newValue)
      Sets this lazy value to the provided value.
      T value()
      Returns the value held by this lazy.
      static <T> Lazy<T> value​(T value)
      Creates a lazy value using the provided constant value.
      static <T> Lazy<T> weak​(T value)
      Creates a lazy value using a weak reference to the provided value.
    • Method Detail

      • value

        T value()
        Returns the value held by this lazy. This may cause the value to initialize if it hasn't been already.
      • get

        default T get()
        Returns the value held by this lazy. This may cause the value to initialize if it hasn't been already.
        Specified by:
        get in interface java.util.function.Supplier<T>
      • map

        default <R> Lazy<R> map​(java.util.function.Function<? super T,​? extends R> function)
        Creates a new lazy value derived from this lazy value using the provided value mapping function.
      • isInitialized

        boolean isInitialized()
        Indicates whether this lazy value has been initialized.
      • set

        void set​(T newValue)
        Sets this lazy value to the provided value.
        Throws:
        java.lang.UnsupportedOperationException - if this type of lazy value cannot be updated
      • lazy

        static <T> Lazy<T> lazy​(java.util.function.Supplier<T> supplier)
        Creates a strict lazy value using the provided Supplier. The supplier is guaranteed to only be invoked by at most one thread, and all threads will see the same published value when this returns.
      • value

        static <T> Lazy<T> value​(T value)
        Creates a lazy value using the provided constant value.
      • weak

        static <T> Lazy<T> weak​(T value)
        Creates a lazy value using a weak reference to the provided value.
      • pure

        static <T> Lazy<T> pure​(java.util.function.Supplier<T> supplier)
        Creates a pure lazy value using the provided Supplier to initialize the value. The supplier may be invoked more than once, and the return value should be a purely computed value as the result may be a different instance each time. This is useful for building cache tables and other pure computations.