Class LazyLoad<T>

java.lang.Object
net.luis.utils.util.LazyLoad<T>
Type Parameters:
T - The type of the value
All Implemented Interfaces:
Supplier<T>

public class LazyLoad<T> extends Object implements Supplier<T>
Represents a lazy-loaded value.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Supplier<T>
    The supplier of the value to be loaded lazily.
    private T
    The cached value of the supplier.
    The value is null if the supplier has not been called yet.
  • Constructor Summary

    Constructors
    Constructor
    Description
    LazyLoad(@NotNull Supplier<T> supplier)
    Constructs a new lazy load with the specified supplier.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    get()
    Gets the cached value.
    If the value has not been loaded yet, it will be loaded first.
    int
     
    boolean
    Checks whether the value has been loaded yet or not.
    void
    Loads the value from the supplier if it has not been loaded yet.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • supplier

      private final Supplier<T> supplier
      The supplier of the value to be loaded lazily.
    • value

      private T value
      The cached value of the supplier.
      The value is null if the supplier has not been called yet.
  • Constructor Details

    • LazyLoad

      public LazyLoad(@NotNull @NotNull Supplier<T> supplier)
      Constructs a new lazy load with the specified supplier.
      Parameters:
      supplier - The supplier of the value to be loaded lazily
      Throws:
      NullPointerException - If the supplier is null
  • Method Details

    • load

      public void load()
      Loads the value from the supplier if it has not been loaded yet.
    • isLoaded

      public boolean isLoaded()
      Checks whether the value has been loaded yet or not.
      Returns:
      True if the value has been loaded, false otherwise
    • get

      public T get()
      Gets the cached value.
      If the value has not been loaded yet, it will be loaded first.
      Specified by:
      get in interface Supplier<T>
      Returns:
      The value
      See Also:
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object