Package org.atlanmod.commons
Class LazyDouble
- java.lang.Object
-
- org.atlanmod.commons.LazyDouble
-
@ParametersAreNonnullByDefault public final class LazyDouble extends Object
An object that automatically loads adoubleby using aDoubleSupplierduring the first call togetAsDouble().
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description doublegetAsDouble()Gets the wrapped value.voidifLoaded(DoubleConsumer consumer)If a value is loaded, invoke the specifiedconsumerwith the value, otherwise do nothing.booleanisLoaded()Returnstrueif the value has been loaded.static LazyDoubleof(double value)Creates a new lazy double with the embed value.voidunload()Unloads the wrapped value.voidupdate(double newValue)Updates the wrapped value.voidupdate(DoubleUnaryOperator updateOperator)Updates the wrapped value with aDoubleUnaryOperator.static LazyDoublewith(DoubleSupplier loadFunction)Creates a new lazy double with theDoubleSupplierto load the embed value.
-
-
-
Method Detail
-
of
@Nonnull public static LazyDouble of(double value)
Creates a new lazy double with the embed value.- Parameters:
value- the embed value- Returns:
- a new lazy object
-
with
@Nonnull public static LazyDouble with(DoubleSupplier loadFunction)
Creates a new lazy double with theDoubleSupplierto load the embed value.- Parameters:
loadFunction- the function used to load the value- Returns:
- a new lazy object
-
getAsDouble
public double getAsDouble()
Gets the wrapped value. On the first call, the object is created.- Returns:
- the value
-
update
public void update(double newValue)
Updates the wrapped value.- Parameters:
newValue- the new value
-
update
public void update(DoubleUnaryOperator updateOperator)
Updates the wrapped value with aDoubleUnaryOperator.- 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(DoubleConsumer 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.
-
-