Class AbstractCopier<A>

  • All Implemented Interfaces:
    Copier
    Direct Known Subclasses:
    JavaSerializationCopier

    public abstract class AbstractCopier<A>
    extends 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.
    • Constructor Detail

      • AbstractCopier

        protected AbstractCopier()
    • Method Detail

      • javaImmutableClasses

        public static Set<Class<?>> javaImmutableClasses()
        Returns the set of Java native classes that are immutable.
      • javaDeepCopyStrategies

        public static Map<Class<?>,​Function<Object,​Object>> javaDeepCopyStrategies()
        Returns the set of Java native classes that are deeply copied.
      • copy

        public <T> T copy​(T object,
                          ClassLoader classLoader)
        Description copied from interface: Copier
        Returns a deep copy of the object.
        Specified by:
        copy in interface Copier
        Type Parameters:
        T - the type of object being copied
        Parameters:
        object - the object to copy
        classLoader - the classloader to instantiate with
        Returns:
        a copy of the object
      • isImmutable

        protected boolean isImmutable​(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​(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
      • roundtrip

        protected <T> T roundtrip​(T object,
                                  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 serialize
        classLoader - the classloader to create the instance with
        Returns:
        the deserialized object
      • serialize

        protected abstract A serialize​(Object object)
        Serializes the object.
        Parameters:
        object - the object to serialize
        Returns:
        the serialized bytes
      • deserialize

        protected abstract Object deserialize​(A data,
                                              ClassLoader classLoader)
        Deserializes the data using the provided classloader.
        Parameters:
        data - the serialized bytes
        classLoader - the classloader to create the instance with
        Returns:
        the deserialized object