java.lang.Object
net.luis.utils.util.LazyLoad<T>
- Type Parameters:
T
- The type of the value
- All Implemented Interfaces:
Supplier<T>
Represents a lazy-loaded value.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
get()
Gets the cached value.
If the value has not been loaded yet, it will be loaded first.int
hashCode()
boolean
isLoaded()
Checks whether the value has been loaded yet or not.void
load()
Loads the value from the supplier if it has not been loaded yet.toString()
-
Field Details
-
supplier
The supplier of the value to be loaded lazily. -
value
The cached value of the supplier.
The value isnull
if the supplier has not been called yet.
-
-
Constructor Details
-
LazyLoad
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
Gets the cached value.
If the value has not been loaded yet, it will be loaded first. -
equals
-
hashCode
public int hashCode() -
toString
-