Package org.dellroad.stuff.java
Class GraphCloneRegistry
java.lang.Object
org.dellroad.stuff.java.GraphCloneRegistry
A registry for copies of
GraphCloneable objects used during graph cloning operations.
A graph clone of a graph of objects is a deep copy without duplicates and preserving reference topology.
See GraphCloneable for a complete description.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends GraphCloneable>
TgetGraphClone(T value) Get the unique clone of a given value during a graph clone operation, creating it if necessary.voidsetGraphClone(GraphCloneable clone) Register the given clone as the unique instance associated with the object currently being cloned.
-
Constructor Details
-
GraphCloneRegistry
public GraphCloneRegistry()
-
-
Method Details
-
getGraphClone
Get the unique clone of a given value during a graph clone operation, creating it if necessary.If the
valuehas already been cloned and registered with this instance, it is returned. Otherwise, a new clone ofvalueis created and registered with this instance by invokingvalue.createGraphClone(), and then returned.If the
valueis null, null is returned.- Type Parameters:
T- object type- Parameters:
value- original value- Returns:
- unique clone of
value, or null ifvalueis null - Throws:
IllegalStateException- ifvalue.createGraphClone()fails to invokesetGraphClone()IllegalStateException- ifvalue.createGraphClone()invokessetGraphClone()more than onceIllegalStateException- ifvalue.createGraphClone()fails to invokesetGraphClone()prior to recursing on otherGraphCloneablefields
-
setGraphClone
Register the given clone as the unique instance associated with the object currently being cloned.The "object currently being cloned" is the
GraphCloneableobject associated with the top-most invocation ofGraphCloneable.createGraphClone()on the Java execution stack.This method should only be invoked within implementations of
GraphCloneable.createGraphClone().- Parameters:
clone- the clone associated with the current object being graph cloned; may be null (but that would be weird)- Throws:
IllegalStateException- if the current thread is not executing within an invocation ofGraphCloneable.createGraphClone()
-