Package org.atlanmod.commons
Class LazyInt
- java.lang.Object
-
- org.atlanmod.commons.LazyInt
-
@ParametersAreNonnullByDefault public final class LazyInt extends Object
An object that automatically loads anintegerby using aIntSupplierduring the first call togetAsInt().
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetAsInt()Gets the wrapped value.voidifLoaded(IntConsumer consumer)If a value is loaded, invoke the specifiedconsumerwith the value, otherwise do nothing.booleanisLoaded()Returnstrueif the value has been loaded.static LazyIntof(int value)Creates a new lazy integer with the embed value.voidunload()Unloads the wrapped value.voidupdate(int newValue)Updates the wrapped value.voidupdate(IntUnaryOperator updateOperator)Updates the wrapped value with aIntUnaryOperator.static LazyIntwith(IntSupplier loadFunction)Creates a new lazy integer with theIntSupplierto load the embed value.
-
-
-
Method Detail
-
of
@Nonnull public static LazyInt of(int value)
Creates a new lazy integer with the embed value.- Parameters:
value- the embed value- Returns:
- a new lazy object
-
with
@Nonnull public static LazyInt with(IntSupplier loadFunction)
Creates a new lazy integer with theIntSupplierto load the embed value.- Parameters:
loadFunction- the function used to load the value- Returns:
- a new lazy object
-
getAsInt
public int getAsInt()
Gets the wrapped value. On the first call, the object is created.- Returns:
- the value
-
update
public void update(int newValue)
Updates the wrapped value.- Parameters:
newValue- the new value
-
update
public void update(IntUnaryOperator updateOperator)
Updates the wrapped value with aIntUnaryOperator.- Parameters:
updateOperator- the operator to update the wrapped value
-
isLoaded
public boolean isLoaded()
Returnstrueif the value has been loaded.- Returns:
trueif the value has been loaded
-
ifLoaded
public void ifLoaded(IntConsumer consumer)
If a value is loaded, invoke the specifiedconsumerwith the value, otherwise do nothing.- Parameters:
consumer- action to be executed if a value is present
-
unload
public void unload()
Unloads the wrapped value. If the value is not loaded, then this method does nothing.
-
-