java.lang.Object
net.luis.utils.util.LazyInitialization<T>
- Type Parameters:
T
- The type of the object to initialize
A class representing a lazy initialization of an object.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructs a new lazy initialization with no value and no initialization action.LazyInitialization
(@NotNull Consumer<T> action) Constructs a new lazy initialization with the given initialization action.private
LazyInitialization
(@NotNull org.apache.commons.lang3.mutable.MutableObject<T> mutable, @NotNull Consumer<T> action, boolean initialised) Constructs a new lazy initialization with the given mutable object and initialization action.LazyInitialization
(T value) Constructs an already initialized lazy initialization with the given value.LazyInitialization
(T value, @NotNull Consumer<T> action) Constructs an already initialized lazy initialization with the given value and initialization action. -
Method Summary
Modifier and TypeMethodDescriptionboolean
get()
Gets the value of the object if it has been initialized.int
hashCode()
boolean
Checks whether the object has been initialized or not.void
Sets the value of the object if it has not been initialized yet.
Performs the action set in the constructor if the object is initialized.toString()
-
Field Details
-
object
The object to be initialized. -
action
The action to perform when the object is initialized. -
initialised
private boolean initialisedWhether the object has been initialized or not.
-
-
Constructor Details
-
LazyInitialization
public LazyInitialization()Constructs a new lazy initialization with no value and no initialization action. -
LazyInitialization
Constructs an already initialized lazy initialization with the given value.- Parameters:
value
- The value to initialize the object with
-
LazyInitialization
Constructs a new lazy initialization with the given initialization action.- Parameters:
action
- The action to perform when the object is initialized- Throws:
NullPointerException
- If the action is null
-
LazyInitialization
Constructs an already initialized lazy initialization with the given value and initialization action.- Parameters:
value
- The value to initialize the object withaction
- The action to perform when the object is initialized- Throws:
NullPointerException
- If the action is null
-
LazyInitialization
private LazyInitialization(@NotNull @NotNull org.apache.commons.lang3.mutable.MutableObject<T> mutable, @NotNull @NotNull Consumer<T> action, boolean initialised) Constructs a new lazy initialization with the given mutable object and initialization action.- Parameters:
mutable
- The internal mutable object to hold the valueaction
- The action to perform when the object is initializedinitialised
- Whether the object has been initialized or not- Throws:
NullPointerException
- If the mutable or action is null- See Also:
-
-
Method Details
-
get
Gets the value of the object if it has been initialized.- Returns:
- The value of the object
- Throws:
NotInitializedException
- If the object has not been initialized yet
-
set
Sets the value of the object if it has not been initialized yet.
Performs the action set in the constructor if the object is initialized.- Parameters:
value
- The value to initialize the object with- Throws:
AlreadyInitializedException
- If the object has already been initialized
-
isInstantiated
public boolean isInstantiated()Checks whether the object has been initialized or not.- Returns:
- True if the object has been initialized, false otherwise
-
equals
-
hashCode
public int hashCode() -
toString
-