Package org.goplanit.utils.misc
Class CloneUtils
- java.lang.Object
-
- org.goplanit.utils.misc.CloneUtils
-
public class CloneUtils extends Object
Some utility methods to use serialization to allow for deep copy cloning without knowing anything about the objects type- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description CloneUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
deepClone(T object)
clone an object by using the serialise/deserialise methods in this class.static <K,V>
Map<K,V>deepCloneFromTo(Map<K,V> sourceMap, Map<K,V> destinationMap)
clone object values (not keys) in source map by using the serialise/deserialise methods in this class.static <T> T
deSerialize(byte[] array)
Deserialise based on byte array to objectstatic byte[]
serialize(Object object)
Serialise an object
-
-
-
Method Detail
-
serialize
public static byte[] serialize(Object object) throws IOException
Serialise an object- Parameters:
object
- to serialise- Returns:
- byte array
- Throws:
IOException
- thrown if error
-
deSerialize
public static <T> T deSerialize(byte[] array) throws IOException, ClassNotFoundException
Deserialise based on byte array to object- Type Parameters:
T
- type to deserialize- Parameters:
array
- to deserialize- Returns:
- object created
- Throws:
IOException
- thrown if errorClassNotFoundException
- thrown if error
-
deepClone
public static <T> T deepClone(T object)
clone an object by using the serialise/deserialise methods in this class. This is a costly operation- Type Parameters:
T
- object type- Parameters:
object
- to clone- Returns:
- cloned version
-
deepCloneFromTo
public static <K,V> Map<K,V> deepCloneFromTo(Map<K,V> sourceMap, Map<K,V> destinationMap)
clone object values (not keys) in source map by using the serialise/deserialise methods in this class. This is a costly operation- Type Parameters:
K
- key typeV
- object value type- Parameters:
sourceMap
- to clonedestinationMap
- to populate- Returns:
- destination map
-
-