Class Lazy.SimpleWeakLazy<T>

java.lang.Object
ru.progrm_jarvis.javacommons.lazy.Lazy.SimpleWeakLazy<T>
Type Parameters:
T - type of wrapped value
All Implemented Interfaces:
Supplier<T>, Lazy<T>
Enclosing interface:
Lazy<T>

public static final class Lazy.SimpleWeakLazy<@NotNull T> extends Object implements Lazy<T>
Non-thread-safe (using double-checked locking) weak lazy getting its value from the specified value supplier.
API note
weak lazy stores the value wrapped in weak reference and so it may be GCed and so the new one might be recomputed using the value supplier
  • Method Details

    • get

      public T get()
      Description copied from interface: Lazy
      Gets the wrapped value initializing it once requested.
      Specified by:
      get in interface Lazy<T>
      Specified by:
      get in interface Supplier<T>
      Returns:
      wrapped value
    • isInitialized

      public boolean isInitialized()
      Description copied from interface: Lazy
      Tests if the value of this lazy was initialized.
      Specified by:
      isInitialized in interface Lazy<T>
      Returns:
      true if this lazy's value was initialize and false otherwise
    • getInitializedOrNull

      @Nullable public T getInitializedOrNull()
      Description copied from interface: Lazy
      Gets the wrapped value if it is already initialized or null otherwise.
      Specified by:
      getInitializedOrNull in interface Lazy<T>
      Returns:
      wrapped value if it is already initialized or null otherwise
      See Also:
    • getAsResult

      @NotNull public @NotNull Result<T,Void> getAsResult()
      Description copied from interface: Lazy
      Gets the wrapped value wrapped in Result if it is already initialized or a Result.nullError() otherwise.
      Specified by:
      getAsResult in interface Lazy<T>
      Returns:
      wrapped value wrapped in Result if it is already initialized or Result.nullError() otherwise