Search this API

y.util
Class GraphCopier

java.lang.Object
  extended by y.util.GraphCopier

public class GraphCopier
extends java.lang.Object

A utility class that can be used to copy a graph's structure and possibly associated data to another instance. This class relies on implementations of GraphCopier.CopyFactory that can either be any of the default implementations or any other implementation that can be associated with a Graph's copy factory property.

See Also:
GraphCopier.CopyFactory, copy(y.base.Graph)
 

Nested Class Summary
static interface GraphCopier.CopyFactory
          The copy factory interface used by GraphCopier to delegate the actual work to.
static class GraphCopier.DataProviderCopyFactory
          Abstract helper class that provides helper methods to copy DataProvider contents.
static class GraphCopier.EdgeDataProviderCopyFactory
          Helper class implementation of GraphCopier.CopyFactory that can be used to copy the contents of a DataProvider registered with the source graph onto the target graph storing the values in newly a created edge map.
static class GraphCopier.EdgeMapCopyFactory
          A helper wrapping implementation of the GraphCopier.CopyFactory interface that copies the contents of the edge maps from the source to the target graph.
static class GraphCopier.GraphDataCopyFactory
          An abstract base implementation of a delegating GraphCopier.GraphDataCopyFactory that copies data for items being copied.
static class GraphCopier.ItemDataProviderCopyFactory
          Helper class implementation of GraphCopier.CopyFactory that can be used to copy the contents of a DataProvider registered with the source graph onto the target graph storing the values in newly created HashMap based DataMaps.
static class GraphCopier.NodeDataProviderCopyFactory
          Helper class implementation of GraphCopier.CopyFactory that can be used to copy the contents of a DataProvider registered with the source graph onto the target graph storing the values in newly created node map.
static class GraphCopier.NodeMapCopyFactory
          A helper wrapping implementation of the GraphCopier.CopyFactory interface that copies the contents of the node maps from the source to the target graph.
 
Constructor Summary
GraphCopier()
          Creates a new instance that uses a GraphCopyFactory as the default factory.
GraphCopier(GraphCopier.CopyFactory copyFactory)
          Creates a new instance that uses the specified factory to perform the actual copy operations.
 
Method Summary
 Graph copy(Graph sourceGraph)
          Copies the contents of the source graph to a newly created target graph and returns the new graph.
 NodeList copy(Graph sourceGraph, Graph targetGraph)
          Copies the contents of the source graph to the target graph and returns the newly created nodes in the target graph.
 Graph copy(Graph sourceGraph, NodeCursor sourceNodes)
          Copies the subgraph contained in graph induced by the source nodes to a newly created graph.
 NodeList copy(Graph sourceGraph, NodeCursor sourceNodes, EdgeCursor sourceEdges, Graph targetGraph)
          Copies the subgraph contained in sourceGraph induced by the source nodes and the provided source edges to the targetGraph.
 NodeList copy(Graph sourceGraph, NodeCursor sourceNodes, Graph targetGraph)
          Copies the subgraph contained in sourceGraph induced by the source nodes to the targetGraph. targetGraph is not cleared prior to the copy operation.
protected  Edge copyEdge(GraphCopier.CopyFactory copyFactory, Graph targetGraph, Node newSource, Node newTarget, Edge edge)
          Callback that uses the given factory to perform the copy operation.
protected  Node copyNode(GraphCopier.CopyFactory copyFactory, Graph targetGraph, Node node)
          Callback that uses the given factory to perform the copy operation.
protected  java.util.Map createEdgeMap()
          Callback that creates the Map that will hold the mapping from the edges in the old source graph to the newly created edges in the target graph.
protected  Graph createGraph(GraphCopier.CopyFactory factory, Graph sourceGraph)
          Callback that uses the given factory to create a new graph.
protected  java.util.Map createNodeMap()
          Callback that creates the Map that will hold the mapping from the nodes in the old source graph to the newly created nodes in the target graph.
 GraphCopier.CopyFactory getCopyFactory()
          Returns the factory that is used for copy operations.
protected  EdgeCursor getSourceEdges(Graph sourceGraph)
          Determines the set of edge candidates from the source graph that should be copied.
protected  NodeCursor getSourceNodes(Graph sourceGraph)
          Determines the set of node candidates from the source graph that should be copied if no other nodes are specified by the user.
 boolean isDataProviderContentCopying()
          Determines if the contents of data providers are copied automatically.
 boolean isEdgeMapCopying()
          Determines if the contents of edge maps are copied automatically.
 boolean isNodeMapCopying()
          Determines if the contents of node maps are copied automatically.
protected  void postCopyGraphData(GraphCopier.CopyFactory copyFactory, Graph sourceGraph, Graph targetGraph, java.util.Map nodeMap, java.util.Map edgeMap)
          Callback that uses the given factory to perform the copy operation.
protected  void preCopyGraphData(GraphCopier.CopyFactory copyFactory, Graph sourceGraph, Graph targetGraph)
          Callback that uses the given factory to perform the copy operation.
 void setCopyFactory(GraphCopier.CopyFactory copyFactory)
          Sets the factory that is used for copy operations.
 void setDataProviderContentCopying(boolean dataProviderContentCopying)
          Specifies if the contents of data providers are copied automatically.
 void setEdgeMapCopying(boolean edgeMapCopying)
          Specifies if the contents of edge maps are copied automatically.
 void setNodeMapCopying(boolean nodeMapCopying)
          Specifies if the contents of node maps are copied automatically.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphCopier

public GraphCopier()
Creates a new instance that uses a GraphCopyFactory as the default factory.


GraphCopier

public GraphCopier(GraphCopier.CopyFactory copyFactory)
Creates a new instance that uses the specified factory to perform the actual copy operations.

Parameters:
copyFactory - the factory to use, must be non-null.
Throws:
java.lang.NullPointerException - if copyFactory is null
Method Detail

isNodeMapCopying

public boolean isNodeMapCopying()
Determines if the contents of node maps are copied automatically.

The default is false.

Returns:
whether to copy node maps and their contents.
See Also:
setNodeMapCopying(boolean)

setNodeMapCopying

public void setNodeMapCopying(boolean nodeMapCopying)
Specifies if the contents of node maps are copied automatically.

The default is false.

Copying will be done by reference on Object basis. To store these objects, new NodeMaps are created for the target graph.

In order to access these NodeMaps it is necessary to store the number of NodeMaps in the target graph before creating the NodeMaps as they will be appended. After copying the graph a NodeMap can be found using this number as offset and add the index of the map in the original graph.

Note: To be able to control and access NodeMaps more easily, it is recommended to use DataProviders instead and have them copied.

Parameters:
nodeMapCopying - whether to copy node maps and their contents.
See Also:
isNodeMapCopying(), GraphCopier.NodeMapCopyFactory, Graph.getRegisteredNodeMaps(), setDataProviderContentCopying(boolean)

isEdgeMapCopying

public boolean isEdgeMapCopying()
Determines if the contents of edge maps are copied automatically.

The default is false.

Returns:
whether to copy edge maps and their contents.
See Also:
setEdgeMapCopying(boolean)

setEdgeMapCopying

public void setEdgeMapCopying(boolean edgeMapCopying)
Specifies if the contents of edge maps are copied automatically.

The default is false.

Copying will be done by reference on Object basis. To store these objects, new EdgeMaps are created for the target graph.

In order to access these EdgeMaps it is necessary to store the number of EdgeMaps in the target graph before creating the EdgeMaps as they will be appended. After copying the graph an EdgeMap can be found using this number as offset and add the index of the map in the original graph.

Note: To be able to control and access EdgeMaps more easily, it is recommended to use DataProviders instead and have them copied.

Parameters:
edgeMapCopying - whether to copy edge maps and their contents.
See Also:
isEdgeMapCopying(), GraphCopier.EdgeMapCopyFactory, Graph.getRegisteredEdgeMaps(), setDataProviderContentCopying(boolean)

isDataProviderContentCopying

public boolean isDataProviderContentCopying()
Determines if the contents of data providers are copied automatically.

The default is false.

Returns:
whether to copy data provider content.
See Also:
setDataProviderContentCopying(boolean)

setDataProviderContentCopying

public void setDataProviderContentCopying(boolean dataProviderContentCopying)
Specifies if the contents of data providers are copied automatically.

The default is false.

Copying will be done by reference on Object basis. The backing store for the content will be HashMap based.

See Also:
GraphCopier.ItemDataProviderCopyFactory, isDataProviderContentCopying()

copy

public NodeList copy(Graph sourceGraph,
                     Graph targetGraph)
Copies the contents of the source graph to the target graph and returns the newly created nodes in the target graph.

Parameters:
sourceGraph - the graph to copy the contents from
targetGraph - the target graph to copy the contents to, it will not be cleared prior to the copying
Returns:
the list of Nodes that have been copied to the target graph.
See Also:
copy(y.base.Graph,y.base.NodeCursor,y.base.Graph)

copy

public Graph copy(Graph sourceGraph)
Copies the contents of the source graph to a newly created target graph and returns the new graph.

Parameters:
sourceGraph - the graph to copy the contents from
Returns:
the newly created graph
See Also:
GraphCopier.CopyFactory.createGraph()

copy

public Graph copy(Graph sourceGraph,
                  NodeCursor sourceNodes)
Copies the subgraph contained in graph induced by the source nodes to a newly created graph.

Parameters:
sourceGraph - the graph to copy
sourceNodes - the nodes in the sourceGraph to copy to the new graph
Returns:
the newly created graph
See Also:
GraphCopier.CopyFactory.createGraph()

getCopyFactory

public GraphCopier.CopyFactory getCopyFactory()
Returns the factory that is used for copy operations.

Returns:
the copy factory as specified in the constructor.
See Also:
setCopyFactory(CopyFactory)

setCopyFactory

public void setCopyFactory(GraphCopier.CopyFactory copyFactory)
Sets the factory that is used for copy operations.

Parameters:
copyFactory - the factory to use, must be non-null.
Throws:
java.lang.NullPointerException - if copyFactory is null
See Also:
getCopyFactory(), GraphCopier(CopyFactory)

createGraph

protected Graph createGraph(GraphCopier.CopyFactory factory,
                            Graph sourceGraph)
Callback that uses the given factory to create a new graph. This method simply delegates to GraphCopier.CopyFactory.createGraph() and can be overwritten to change the behavior.

Parameters:
factory - the factory to use for the creation
sourceGraph - the graph that will be
Returns:
the newly created graph

copy

public NodeList copy(Graph sourceGraph,
                     NodeCursor sourceNodes,
                     Graph targetGraph)
Copies the subgraph contained in sourceGraph induced by the source nodes to the targetGraph. targetGraph is not cleared prior to the copy operation.

Parameters:
sourceGraph - the graph to copy
sourceNodes - the nodes in the sourceGraph to copy to the new graph
targetGraph - the graph to copy the sourceGraph's contents to
Returns:
the list of the new nodes in targetGraph

copy

public NodeList copy(Graph sourceGraph,
                     NodeCursor sourceNodes,
                     EdgeCursor sourceEdges,
                     Graph targetGraph)
Copies the subgraph contained in sourceGraph induced by the source nodes and the provided source edges to the targetGraph. targetGraph is not cleared prior to the copy operation.

Parameters:
sourceGraph - the graph to copy
sourceNodes - the nodes in the sourceGraph to copy to the new graph
targetGraph - the graph to copy the sourceGraph's contents to
sourceEdges - the edges in the sourceGraph to copy to the new graph
Returns:
the list of the new nodes in targetGraph

preCopyGraphData

protected void preCopyGraphData(GraphCopier.CopyFactory copyFactory,
                                Graph sourceGraph,
                                Graph targetGraph)
Callback that uses the given factory to perform the copy operation. This method simply delegates to GraphCopier.CopyFactory.preCopyGraphData(y.base.Graph,y.base.Graph) and can be overwritten to change the behavior.

Parameters:
copyFactory - the factory delegate the operation to

postCopyGraphData

protected void postCopyGraphData(GraphCopier.CopyFactory copyFactory,
                                 Graph sourceGraph,
                                 Graph targetGraph,
                                 java.util.Map nodeMap,
                                 java.util.Map edgeMap)
Callback that uses the given factory to perform the copy operation. This method simply delegates to GraphCopier.CopyFactory.postCopyGraphData(y.base.Graph,y.base.Graph,java.util.Map,java.util.Map) and can be overwritten to change the behavior.

Parameters:
copyFactory - the factory delegate the operation to

createEdgeMap

protected java.util.Map createEdgeMap()
Callback that creates the Map that will hold the mapping from the edges in the old source graph to the newly created edges in the target graph.

Returns:
A map that can be used to store the mapping.

copyEdge

protected Edge copyEdge(GraphCopier.CopyFactory copyFactory,
                        Graph targetGraph,
                        Node newSource,
                        Node newTarget,
                        Edge edge)
Callback that uses the given factory to perform the copy operation. This method simply delegates to GraphCopier.CopyFactory.copyEdge(y.base.Graph,y.base.Node,y.base.Node,y.base.Edge) and can be overwritten to change the behavior.

Parameters:
copyFactory - the factory delegate the operation to

getSourceEdges

protected EdgeCursor getSourceEdges(Graph sourceGraph)
Determines the set of edge candidates from the source graph that should be copied. Note that if any of the source or target node is not present in the target graph the edge will not be copied. This implementation simply returns Graph.edges()

Parameters:
sourceGraph - the graph to determine the edges to copy
Returns:
the edges to copy

copyNode

protected Node copyNode(GraphCopier.CopyFactory copyFactory,
                        Graph targetGraph,
                        Node node)
Callback that uses the given factory to perform the copy operation. This method simply delegates to GraphCopier.CopyFactory.copyNode(y.base.Graph, y.base.Node) and can be overwritten to change the behavior.

Parameters:
copyFactory - the factory delegate the operation to

createNodeMap

protected java.util.Map createNodeMap()
Callback that creates the Map that will hold the mapping from the nodes in the old source graph to the newly created nodes in the target graph.

Returns:
A map that can be used to store the mapping.

getSourceNodes

protected NodeCursor getSourceNodes(Graph sourceGraph)
Determines the set of node candidates from the source graph that should be copied if no other nodes are specified by the user. This implementation simply returns Graph.nodes()

Parameters:
sourceGraph - the graph to determine the nodes to copy
Returns:
the nodes to copy

© Copyright 2000-2019,
yWorks GmbH.
All rights reserved.