TUM CCSM Commons

edu.tum.cs.commons.test
Class DeepCloneTestUtils

java.lang.Object
  extended by edu.tum.cs.commons.test.DeepCloneTestUtils

public class DeepCloneTestUtils
extends java.lang.Object

This class provides various utility methods used to test deep cloning implementations

Version:
$Rev: 27815 $
Author:
deissenb, $Author: hummelb $
Rating:
GREEN Hash: ED526603069BA695A145272D022B02D1

Constructor Summary
DeepCloneTestUtils()
           
 
Method Summary
static java.util.IdentityHashMap<java.lang.Object,java.lang.Object> buildCloneMap(java.lang.Object orig, java.lang.Object clone, java.util.Comparator<java.lang.Object> comparator, java.lang.String... packagePrefixes)
          This method is used to test deep cloning implementations.
static
<T> IdentityHashSet<T>
getAllReferencedObjects(java.lang.Object root, java.lang.Class<T> type, java.lang.String... packagePrefixes)
          This works analogous to getAllReferencedObjects(Object, String...) but allows to limit the results to a certain type.
static IdentityHashSet<java.lang.Object> getAllReferencedObjects(java.lang.Object root, java.lang.String... packagePrefixes)
          Get all objects an object references.
static
<I extends java.lang.Comparable<I>>
java.util.IdentityHashMap<java.lang.Object,java.lang.Object>
testDeepCloning(java.lang.Object orig, java.lang.Object clone, IIdProvider<I,java.lang.Object> idProvider, java.lang.String... packagePrefixes)
          This method uses buildCloneMap(Object, Object, Comparator, String...) to build a map between the original object network and clone network.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DeepCloneTestUtils

public DeepCloneTestUtils()
Method Detail

buildCloneMap

public static java.util.IdentityHashMap<java.lang.Object,java.lang.Object> buildCloneMap(java.lang.Object orig,
                                                                                         java.lang.Object clone,
                                                                                         java.util.Comparator<java.lang.Object> comparator,
                                                                                         java.lang.String... packagePrefixes)
This method is used to test deep cloning implementations. Provided with two object, the original and the clone, it automatically traverses the networks attached to both objects and establishes a mapping between the objects of both networks.

To achieve this, the method uses reflection to determine the methods that define the object networks, typically examples are getChildren() or getParent(). To limit the selection of methods, a list of package prefixes may specified. Only methods that do return a type matched by one of the prefixes are taken into account. Additionally all methods that return an implementation of Collection are considered. However, we currently do not consider nested collections like Set.

To establish the mapping between the networks a comparator is needed to order members of object in both networks in the same way. This comparator must not be capable of comparing all possible types but must support ordering possible member type combinations of the object network under investigation. Usually, the object already provide some means of identification via IDs or full qualified names. These can be used to implement the comparator.

Parameters:
orig - point of entry for the original network
clone - point of entry for the clone network
comparator - the comparator is needed to compare the two networks
packagePrefixes - list of package prefixes to take into account

getAllReferencedObjects

public static <T> IdentityHashSet<T> getAllReferencedObjects(java.lang.Object root,
                                                             java.lang.Class<T> type,
                                                             java.lang.String... packagePrefixes)
This works analogous to getAllReferencedObjects(Object, String...) but allows to limit the results to a certain type.


getAllReferencedObjects

public static IdentityHashSet<java.lang.Object> getAllReferencedObjects(java.lang.Object root,
                                                                        java.lang.String... packagePrefixes)
Get all objects an object references. To to find the objects, this method uses reflection to determine the methods that define the object networks, typically examples are getChildren() or getParent(). To limit the selection of methods, a list of package prefixes must be specified. Only methods that do return a type matched by one of the prefixes are taken into account. Additionally all methods that return an implementation of Collection are considered.

Parameters:
root - root of the object network
packagePrefixes - list of package prefixes to take into account

testDeepCloning

public static <I extends java.lang.Comparable<I>> java.util.IdentityHashMap<java.lang.Object,java.lang.Object> testDeepCloning(java.lang.Object orig,
                                                                                                                               java.lang.Object clone,
                                                                                                                               IIdProvider<I,java.lang.Object> idProvider,
                                                                                                                               java.lang.String... packagePrefixes)
This method uses buildCloneMap(Object, Object, Comparator, String...) to build a map between the original object network and clone network. Based on this map it performs the following checks:

Parameters:
orig - point of entry for the original network
clone - point of entry for the clone network
idProvider - an id provider that generates an id for all objects in the networks. This is necessary to establish comparable orderings.
packagePrefixes - list of package prefixes to take into account
Returns:
the map to allow further tests.

TUM CCSM Commons

TUM CCSM Commons - 2.7