Package org.atlanmod.commons
Class Lazy<T>
- java.lang.Object
-
- org.atlanmod.commons.Lazy<T>
-
- Type Parameters:
T- the type of the embed value
@ParametersAreNonnullByDefault public final class Lazy<T> extends Object
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Tget()Gets the wrapped value.voidifLoaded(Consumer<T> consumer)If a value is loaded, invoke the specifiedconsumerwith the value, otherwise do nothing.booleanisLoaded()Returnstrueif the value has been loaded.static <T> Lazy<T>of(T value)Creates a new lazy object with the embed value.voidunload()Unloads the wrapped value.voidupdate(UnaryOperator<T> updateOperator)Updates the wrapped value with aUnaryOperator.voidupdate(T newValue)Updates the wrapped value.static <T> Lazy<T>with(Supplier<T> loadFunction)Creates a new lazy object with theSupplierto load the embed value.
-
-
-
Method Detail
-
of
@Nonnull public static <T> Lazy<T> of(T value)
Creates a new lazy object with the embed value.- Type Parameters:
T- the type of the embed value- Parameters:
value- the embed value- Returns:
- a new lazy object
-
with
@Nonnull public static <T> Lazy<T> with(Supplier<T> loadFunction)
Creates a new lazy object with theSupplierto load the embed value.- Type Parameters:
T- the type of the embed value- Parameters:
loadFunction- the function used to load the value- Returns:
- a new lazy object
-
get
public T get()
Gets the wrapped value. On the first call, the object is created.- Returns:
- the value
-
update
public void update(@Nullable T newValue)Updates the wrapped value.- Parameters:
newValue- the new value
-
update
public void update(UnaryOperator<T> updateOperator)
Updates the wrapped value with aUnaryOperator.- 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(Consumer<T> 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.
-
-