V - Cache instance value typepublic abstract class CacheValue<V> extends Object
Reference,
depending on the current "strength" when getInstance() was called.
The value is conceptually immutable. If it is held via a direct reference, then it is actually immutable.
A Reference may be cleared (garbage-collected),
after which get() returns null.
It can then be reset via resetIfAbsent().
The new value should be the same as, or equivalent to, the old value.
Null values are supported. They can be distinguished from cleared values
via isNull().
| Modifier and Type | Class and Description |
|---|---|
static class |
CacheValue.Strength
"Strength" of holding a value in CacheValue instances.
|
| Constructor and Description |
|---|
CacheValue() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
futureInstancesWillBeStrong()
Returns true if the "strength" is set to
STRONG. |
abstract V |
get()
Returns the value (which can be null),
or null if it was held in a Reference and has been cleared.
|
static <V> CacheValue<V> |
getInstance(V value)
Returns a CacheValue instance that holds the value.
|
boolean |
isNull()
Distinguishes a null value from a Reference value that has been cleared.
|
abstract V |
resetIfCleared(V value)
|
static void |
setStrength(CacheValue.Strength strength)
Changes the "strength" of value references for subsequent
getInstance() calls. |
public static void setStrength(CacheValue.Strength strength)
getInstance() calls.public static boolean futureInstancesWillBeStrong()
STRONG.public static <V> CacheValue<V> getInstance(V value)
STRONG.
Otherwise, it holds it via a Reference.public boolean isNull()
public abstract V get()
public abstract V resetIfCleared(V value)
Reference which has been cleared,
then it is replaced with a new Reference to the new value,
and the new value is returned.
The old and new values should be the same or equivalent.
Otherwise the old value is returned.
value - Replacement value, for when the current Reference has been cleared.