TUM CCSM Commons

edu.tum.cs.commons.clone
Class CloneUtils

java.lang.Object
  extended by edu.tum.cs.commons.clone.CloneUtils

public class CloneUtils
extends java.lang.Object

Collection of utility methods to simplify cloning.

Version:
$Rev: 26268 $
Author:
Benjamin Hummel, $Author: juergens $
Rating:
GREEN Hash: 67F5FD6BA376F3700299C536C919917E

Constructor Summary
CloneUtils()
           
 
Method Summary
static java.lang.Object cloneAsDeepAsPossible(java.lang.Object o)
          Clone the provided object if supported.
static java.lang.Object cloneAsDeepAsPossible(java.lang.Object o, int maxDepth)
          Clone the provided object if supported.
static void cloneMapEntries(java.util.Map<java.lang.String,java.lang.Object> source, java.util.Map<java.lang.String,java.lang.Object> target)
          Duplicate all entries of the source map to the target map and create clones of all contained objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CloneUtils

public CloneUtils()
Method Detail

cloneMapEntries

public static void cloneMapEntries(java.util.Map<java.lang.String,java.lang.Object> source,
                                   java.util.Map<java.lang.String,java.lang.Object> target)
                            throws DeepCloneException
Duplicate all entries of the source map to the target map and create clones of all contained objects.

Parameters:
source - the source for the key value pairs.
target - the map to insert the created clones into.
Throws:
DeepCloneException

cloneAsDeepAsPossible

public static java.lang.Object cloneAsDeepAsPossible(java.lang.Object o)
                                              throws DeepCloneException
Clone the provided object if supported. If the depth of the structure is deeper than 3 an exception is thrown. For some of the special cases handled see cloneAsDeepAsPossible(Object, int).

Parameters:
o - the object to be cloned.
Returns:
the cloned (or original) object.
Throws:
DeepCloneException - if the depth of the cloned struture is too high or the underlying clone methods failed.

cloneAsDeepAsPossible

public static java.lang.Object cloneAsDeepAsPossible(java.lang.Object o,
                                                     int maxDepth)
                                              throws DeepCloneException
Clone the provided object if supported. The following cases are explicitly handled:

Parameters:
o - the object to be cloned.
maxDepth - the maximal depth of the structure before an exception is thrown. A depth of 0 indicates that no recursive calls are allowed, depth 1 allows 1 recursive call, and so on.
Returns:
the cloned (or original) object.
Throws:
DeepCloneException - if the depth of the cloned struture is too high or the underlying clone methods failed.

TUM CCSM Commons

TUM CCSM Commons - 2.7