Package org.jivesoftware.util
Class CacheableOptional<T extends Serializable>
- java.lang.Object
-
- org.jivesoftware.util.CacheableOptional<T>
-
- All Implemented Interfaces:
Serializable
,Cacheable
public class CacheableOptional<T extends Serializable> extends Object implements Cacheable
Some times it is desirable to store in aCache
the absence of a value. Unfortunately, it's not possible to store anull
value in a clustered cache because of the underlying hazelcast technology used for clustering. The obvious candidate would therefore be to store anOptional
object in the cache instead - unfortunately an Optional is not serializable. This class therefore performs this functionality - an optional value that is cacheable.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
static <T extends Serializable>
CacheableOptional<T>from(Optional<T> value)
T
get()
int
getCachedSize()
Returns the approximate size of the Object in bytes.int
hashCode()
boolean
isAbsent()
boolean
isPresent()
static <T extends Serializable>
CacheableOptional<T>of(T value)
Optional<T>
toOptional()
String
toString()
-
-
-
Method Detail
-
of
public static <T extends Serializable> CacheableOptional<T> of(T value)
-
from
public static <T extends Serializable> CacheableOptional<T> from(Optional<T> value)
-
get
public T get()
-
isPresent
public boolean isPresent()
-
isAbsent
public boolean isAbsent()
-
getCachedSize
public int getCachedSize() throws CannotCalculateSizeException
Description copied from interface:Cacheable
Returns the approximate size of the Object in bytes. The size should be considered to be a best estimate of how much memory the Object occupies and may be based on empirical trials or dynamic calculations.- Specified by:
getCachedSize
in interfaceCacheable
- Returns:
- the size of the Object in bytes.
- Throws:
CannotCalculateSizeException
- if the size cannot be calculated
-
-