Package org.beanio.internal.util
Class Replicator
- java.lang.Object
-
- org.beanio.internal.util.Replicator
-
public class Replicator extends java.lang.Object
Utility class used to copy a hierarchical object graph.If all nodes in the graph implement
Replicateable
and are registered usingregister(Replicateable)
, callingreplicate(Object)
and passing the root node in the graph will clone all registered nodes and return a copy of the root node with references to copies of its descendents.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description Replicator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
register(Replicateable node)
Registers a node in a graph that can be copied.<T> T
replicate(T value)
Returns a copy of the registered graph node and its descendants.
-
-
-
Method Detail
-
register
public void register(Replicateable node)
Registers a node in a graph that can be copied.- Parameters:
node
- the graph node to register
-
replicate
public <T> T replicate(T value)
Returns a copy of the registered graph node and its descendants. This method will clone all registered nodes allow each node to update its references.- Type Parameters:
T
- the node type- Parameters:
value
- the root graph node- Returns:
- a copy of the root graph node and its descendants
- Throws:
java.lang.IllegalStateException
- ifvalue
is not a registered node
-
-