Package org.atlanmod.commons
Class LazyReference<T>
- java.lang.Object
-
- org.atlanmod.commons.LazyReference<T>
-
- Type Parameters:
T- the type of the embed value
@ParametersAreNonnullByDefault public abstract class LazyReference<T> extends Object
An object that automatically loads an object of typeTby using aSupplier. The value is wrapped in aReferencethat is automatically refreshed on-demand when it has been cleared, either by the program or by the garbage collector.- See Also:
Reference
-
-
Constructor Summary
Constructors Constructor Description LazyReference(Supplier<T> refreshFunction)Constructs a newLazyReference.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Tget()Gets the value.protected abstract Reference<T>newReference(T value)Creates a newReferencefor the givenvalue.static <T> LazyReference<T>soft(Supplier<T> refreshFunction)Creates a new lazy reference that usesSoftReference.voidupdate(T newValue)Updates the value.static <T> LazyReference<T>weak(Supplier<T> refreshFunction)Creates a new lazy reference that usesWeakReference.
-
-
-
Method Detail
-
soft
public static <T> LazyReference<T> soft(Supplier<T> refreshFunction)
Creates a new lazy reference that usesSoftReference.- Type Parameters:
T- the type of the embed value- Parameters:
refreshFunction- the function used to refresh the value- Returns:
- a new lazy reference
-
weak
public static <T> LazyReference<T> weak(Supplier<T> refreshFunction)
Creates a new lazy reference that usesWeakReference.- Type Parameters:
T- the type of the embed value- Parameters:
refreshFunction- the function used to refresh the value- Returns:
- a new lazy reference
-
get
public T get()
Gets the value.- Returns:
- the value
-
update
public void update(@Nullable T newValue)Updates the value.- Parameters:
newValue- the new value
-
-