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 aCachethe absence of a value. Unfortunately, it's not possible to store anullvalue in a clustered cache because of the underlying hazelcast technology used for clustering. The obvious candidate would therefore be to store anOptionalobject 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 booleanequals(Object o)static <T extends Serializable>
CacheableOptional<T>from(Optional<T> value)Tget()intgetCachedSize()Returns the approximate size of the Object in bytes.inthashCode()booleanisAbsent()booleanisPresent()static <T extends Serializable>
CacheableOptional<T>of(T value)Optional<T>toOptional()
-
-
-
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 CannotCalculateSizeExceptionDescription copied from interface:CacheableReturns 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:
getCachedSizein interfaceCacheable- Returns:
- the size of the Object in bytes.
- Throws:
CannotCalculateSizeException- if the size cannot be calculated
-
-