Package org.atlanmod.commons
Class LazyBoolean
- java.lang.Object
-
- org.atlanmod.commons.LazyBoolean
-
@ParametersAreNonnullByDefault public final class LazyBoolean extends Object
An object that automatically loads abooleanby using aBooleanSupplierduring the first call togetAsBoolean().
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleangetAsBoolean()Gets the wrapped value.booleanisLoaded()Returnstrueif the value has been loaded.static LazyBooleanof(boolean value)Creates a new lazy boolean with the embed value.voidunload()Unloads the wrapped value.voidupdate(boolean newValue)Updates the wrapped value.static LazyBooleanwith(BooleanSupplier loadFunction)Creates a new lazy boolean with theBooleanSupplierto load the embed value.
-
-
-
Method Detail
-
of
@Nonnull public static LazyBoolean of(boolean value)
Creates a new lazy boolean with the embed value.- Parameters:
value- the embed value- Returns:
- a new lazy object
-
with
@Nonnull public static LazyBoolean with(BooleanSupplier loadFunction)
Creates a new lazy boolean with theBooleanSupplierto load the embed value.- Parameters:
loadFunction- the function used to load the value- Returns:
- a new lazy boolean
-
getAsBoolean
public boolean getAsBoolean()
Gets the wrapped value. On the first call, the object is created.- Returns:
- the value
-
update
public void update(boolean newValue)
Updates the wrapped value.- Parameters:
newValue- the new value
-
isLoaded
public boolean isLoaded()
Returnstrueif the value has been loaded.- Returns:
trueif the value has been loaded
-
unload
public void unload()
Unloads the wrapped value. If the value is not loaded, then this method does nothing.
-
-