Class AbstractCopier<A>
- java.lang.Object
-
- com.github.benmanes.caffeine.jcache.copy.AbstractCopier<A>
-
- All Implemented Interfaces:
Copier
- Direct Known Subclasses:
JavaSerializationCopier
public abstract class AbstractCopier<A> extends java.lang.Object implements Copier
A skeleton implementation where subclasses provide the serialization strategy. Serialization is not performed if the type is a known immutable, an array of known immutable types, or specially handled by a known cloning strategy.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Class<?>,java.util.function.Function<java.lang.Object,java.lang.Object>>
deepCopyStrategies
private java.util.Set<java.lang.Class<?>>
immutableClasses
private static java.util.Map<java.lang.Class<?>,java.util.function.Function<java.lang.Object,java.lang.Object>>
JAVA_DEEP_COPY
private static java.util.Set<java.lang.Class<?>>
JAVA_IMMUTABLE
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractCopier()
protected
AbstractCopier(java.util.Set<java.lang.Class<?>> immutableClasses, java.util.Map<java.lang.Class<?>,java.util.function.Function<java.lang.Object,java.lang.Object>> deepCopyStrategies)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private static <T> T
arrayCopy(T object)
protected boolean
canDeeplyCopy(java.lang.Class<?> clazz)
Returns if the class has a known deep copy strategy.<T> T
copy(T object, java.lang.ClassLoader classLoader)
Returns a deep copy of the object.private <T> T
deepCopy(T object)
protected abstract java.lang.Object
deserialize(A data, java.lang.ClassLoader classLoader)
Deserializes the data using the provided classloader.private boolean
isArrayOfImmutableTypes(java.lang.Class<?> clazz)
protected boolean
isImmutable(java.lang.Class<?> clazz)
Returns if the class is an immutable type and does not need to be copied.static java.util.Map<java.lang.Class<?>,java.util.function.Function<java.lang.Object,java.lang.Object>>
javaDeepCopyStrategies()
static java.util.Set<java.lang.Class<?>>
javaImmutableClasses()
protected <T> T
roundtrip(T object, java.lang.ClassLoader classLoader)
Performs the serialization and deserialization, returning the copied object.protected abstract A
serialize(java.lang.Object object)
Serializes the object.
-
-
-
Field Detail
-
JAVA_DEEP_COPY
private static final java.util.Map<java.lang.Class<?>,java.util.function.Function<java.lang.Object,java.lang.Object>> JAVA_DEEP_COPY
-
JAVA_IMMUTABLE
private static final java.util.Set<java.lang.Class<?>> JAVA_IMMUTABLE
-
immutableClasses
private final java.util.Set<java.lang.Class<?>> immutableClasses
-
deepCopyStrategies
private final java.util.Map<java.lang.Class<?>,java.util.function.Function<java.lang.Object,java.lang.Object>> deepCopyStrategies
-
-
Method Detail
-
javaImmutableClasses
public static java.util.Set<java.lang.Class<?>> javaImmutableClasses()
- Returns:
- the set of Java native classes that are immutable
-
javaDeepCopyStrategies
public static java.util.Map<java.lang.Class<?>,java.util.function.Function<java.lang.Object,java.lang.Object>> javaDeepCopyStrategies()
- Returns:
- the set of Java native classes that are deeply copied.
-
copy
public <T> T copy(T object, java.lang.ClassLoader classLoader)
Description copied from interface:Copier
Returns a deep copy of the object.
-
isImmutable
protected boolean isImmutable(java.lang.Class<?> clazz)
Returns if the class is an immutable type and does not need to be copied.- Parameters:
clazz
- the class of the object being copied- Returns:
- if the class is an immutable type and does not need to be copied
-
canDeeplyCopy
protected boolean canDeeplyCopy(java.lang.Class<?> clazz)
Returns if the class has a known deep copy strategy.- Parameters:
clazz
- the class of the object being copied- Returns:
- if the class has a known deep copy strategy
-
isArrayOfImmutableTypes
private boolean isArrayOfImmutableTypes(java.lang.Class<?> clazz)
- Returns:
- if the class represents an array of immutable values.
-
arrayCopy
private static <T> T arrayCopy(T object)
- Returns:
- a shallow copy of the array.
-
deepCopy
private <T> T deepCopy(T object)
- Returns:
- a deep copy of the object.
-
roundtrip
protected <T> T roundtrip(T object, java.lang.ClassLoader classLoader)
Performs the serialization and deserialization, returning the copied object.- Type Parameters:
T
- the type of object being copied- Parameters:
object
- the object to serializeclassLoader
- the classloader to create the instance with- Returns:
- the deserialized object
-
serialize
protected abstract A serialize(java.lang.Object object)
Serializes the object.- Parameters:
object
- the object to serialize- Returns:
- the serialized bytes
-
deserialize
protected abstract java.lang.Object deserialize(A data, java.lang.ClassLoader classLoader)
Deserializes the data using the provided classloader.- Parameters:
data
- the serialized bytesclassLoader
- the classloader to create the instance with- Returns:
- the deserialized object
-
-