Class 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 using register(Replicateable), calling replicate(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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Replicator

        public Replicator()
    • 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 - if value is not a registered node