Package org.atlanmod.commons
Class LazyLong
- java.lang.Object
-
- org.atlanmod.commons.LazyLong
-
@ParametersAreNonnullByDefault public final class LazyLong extends Object
An object that automatically loads alongby using aLongSupplierduring the first call togetAsLong().
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetAsLong()Gets the wrapped value.voidifLoaded(LongConsumer consumer)If a value is loaded, invoke the specifiedconsumerwith the value, otherwise do nothing.booleanisLoaded()Returnstrueif the value has been loaded.static LazyLongof(long value)Creates a new lazy long with the embed value.voidunload()Unloads the wrapped value.voidupdate(long newValue)Updates the wrapped value.voidupdate(LongUnaryOperator updateOperator)Updates the wrapped value with aLongUnaryOperator.static LazyLongwith(LongSupplier loadFunction)Creates a new lazy long with theLongSupplierto load the embed value.
-
-
-
Method Detail
-
of
@Nonnull public static LazyLong of(long value)
Creates a new lazy long with the embed value.- Parameters:
value- the embed value- Returns:
- a new lazy object
-
with
@Nonnull public static LazyLong with(LongSupplier loadFunction)
Creates a new lazy long with theLongSupplierto load the embed value.- Parameters:
loadFunction- the function used to load the value- Returns:
- a new lazy object
-
getAsLong
public long getAsLong()
Gets the wrapped value. On the first call, the object is created.- Returns:
- the value
-
update
public void update(long newValue)
Updates the wrapped value.- Parameters:
newValue- the new value
-
update
public void update(LongUnaryOperator updateOperator)
Updates the wrapped value with aLongUnaryOperator.- 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(LongConsumer 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.
-
-