Package com.ibm.icu.impl
Class CacheValue<V>
- java.lang.Object
-
- com.ibm.icu.impl.CacheValue<V>
-
- Type Parameters:
V
- Cache instance value type
- Direct Known Subclasses:
CacheValue.NullValue
,CacheValue.SoftValue
,CacheValue.StrongValue
public abstract class CacheValue<V> extends java.lang.Object
Value type for cache items: Holds a value either via a direct reference or via aReference
, depending on the current "strength" whengetInstance()
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 whichget()
returns null. It can then be reset viaresetIfAbsent()
. 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()
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
CacheValue.NullValue<V>
private static class
CacheValue.SoftValue<V>
static class
CacheValue.Strength
"Strength" of holding a value in CacheValue instances.private static class
CacheValue.StrongValue<V>
-
Field Summary
Fields Modifier and Type Field Description private static CacheValue
NULL_VALUE
private static CacheValue.Strength
strength
-
Constructor Summary
Constructors Constructor Description CacheValue()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static boolean
futureInstancesWillBeStrong()
Returns true if the "strength" is set toSTRONG
.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)
If the value was held via aReference
which has been cleared, then it is replaced with a newReference
to the new value, and the new value is returned.static void
setStrength(CacheValue.Strength strength)
Changes the "strength" of value references for subsequentgetInstance()
calls.
-
-
-
Field Detail
-
strength
private static volatile CacheValue.Strength strength
-
NULL_VALUE
private static final CacheValue NULL_VALUE
-
-
Method Detail
-
setStrength
public static void setStrength(CacheValue.Strength strength)
Changes the "strength" of value references for subsequentgetInstance()
calls.
-
futureInstancesWillBeStrong
public static boolean futureInstancesWillBeStrong()
Returns true if the "strength" is set toSTRONG
.
-
getInstance
public static <V> CacheValue<V> getInstance(V value)
Returns a CacheValue instance that holds the value. It holds it directly if the value is null or if the current "strength" isSTRONG
. Otherwise, it holds it via aReference
.
-
isNull
public boolean isNull()
Distinguishes a null value from a Reference value that has been cleared.- Returns:
- true if this object represents a null value.
-
get
public abstract V get()
Returns the value (which can be null), or null if it was held in a Reference and has been cleared.
-
resetIfCleared
public abstract V resetIfCleared(V value)
If the value was held via aReference
which has been cleared, then it is replaced with a newReference
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.
- Parameters:
value
- Replacement value, for when the currentReference
has been cleared.- Returns:
- The old or new value.
-
-