public class YGraphAdapter extends Object
IGraph instance into a Graph instance.
This class creates a structural copy of a given IGraph and provides convenience methods to convert items from
one graph instance to their corresponding item in the other graph instance.
The main use case of this class is executing one of the analysis algorithms on an IGraph, for example
ShortestPaths, Cycles, and
Centrality. For executing a layout algorithm, use the convenience class
LayoutExecutor, the convenience methods IGraph.applyLayout(ILayoutAlgorithm, LayoutData) and
GraphControl.morphLayout(ILayoutAlgorithm, java.time.Duration, com.yworks.yfiles.utils.IEventHandler),
or LayoutGraphAdapter.
| Constructor and Description |
|---|
YGraphAdapter(IGraph originalGraph)
Initializes a new instance of the
YGraphAdapter class. |
| Modifier and Type | Method and Description |
|---|---|
<K,V> IDataMap |
createDataMap(Class<K> kType,
Class<V> vType,
IMapper<K,V> mapper)
|
<K,V> IDataProvider |
createDataProvider(Class<K> kType,
Function<K,V> getter)
Creates an
IDataProvider that delegates to the provided delegate when queried for items in the
YGraph. |
<K,V> IDataProvider |
createDataProvider(Class<K> kType,
IMapper<K,V> mapper)
Creates an
IDataProvider that delegates to the provided IMapper when queried for items in the
YGraph. |
IListEnumerable<IEdge> |
createEdgeEnumerable(EdgeList edges)
|
EdgeList |
createEdgeList(Iterable<IEdge> edges)
|
<V> IEdgeMap |
createEdgeMap(Function<IEdge,V> getter)
|
<V> IEdgeMap |
createEdgeMap(IMapper<IEdge,V> mapper)
|
<T> IMapper<IModelItem,T> |
createMapper(IDataProvider dataProvider)
Creates an
IMapper that delegates to the provided IDataProvider when queried for items in the
IGraph. |
<T> IMapper<IEdge,T> |
createMapper(IEdgeMap edgeMap)
|
<T> IMapper<INode,T> |
createMapper(INodeMap nodeMap)
|
IListEnumerable<INode> |
createNodeEnumerable(NodeList nodes)
|
NodeList |
createNodeList(Iterable<INode> nodes)
|
<V> INodeMap |
createNodeMap(Function<INode,V> getter)
|
<V> INodeMap |
createNodeMap(IMapper<INode,V> mapper)
|
Edge |
getCopiedEdge(IEdge edge)
Yields the edge that has been created as a copy in
YGraph to represent the given edge. |
Node |
getCopiedNode(INode node)
Yields the node that has been created as a copy in
YGraph to represent the given node. |
IEdge |
getOriginalEdge(Edge edge)
Yields the original edge from the
original IGraph that the given edge has been created for. |
IGraph |
getOriginalGraph()
Gets the original graph instance.
|
INode |
getOriginalNode(Node node)
Yields the original node from the
original IGraph that the given node has been created for. |
Graph |
getYGraph()
Gets the graph instance that is created during the constructor call.
|
public YGraphAdapter(IGraph originalGraph)
YGraphAdapter class.
This will create a copy of the originalGraph that has the same structure and makes it available via the YGraph
property.
originalGraph - The original graph whose structure will be copied.public final <K,V> IDataMap createDataMap(Class<K> kType, Class<V> vType, IMapper<K,V> mapper)
IDataMap that delegates to the provided IMapper when queried for items in the
YGraph.
This method is useful where algorithms require IDataMaps as input and that input can be obtained from IMapper
instances that provide and accept values for the original nodes and
edges.
K - The type of the keys in the mapper.V - The type of the values in the mapper.vType - The type of the values in the mapper.kType - The type of the keys in the mapper.mapper - The mapper to direct requests to.IDataMap that will delegate the functionality to the mapper.createDataProvider(Class, IMapper)public final <K,V> IDataProvider createDataProvider(Class<K> kType, Function<K,V> getter)
IDataProvider that delegates to the provided delegate when queried for items in the
YGraph.
This method is useful where algorithms require IDataProviders as input and that input can be through a dynamic
callback that provides the values for the original nodes and
edges.
K - The type of the keys in the mapper.V - The type of the values in the mapper.kType - The type of the keys in the mapper.getter - The mapper delegate to direct requests to.getter.public final <K,V> IDataProvider createDataProvider(Class<K> kType, IMapper<K,V> mapper)
IDataProvider that delegates to the provided IMapper when queried for items in the
YGraph.
This method is useful where algorithms require IDataProviders as input and that input can be obtained from IMapper
instances that provide the values for the original nodes and
edges.
K - The type of the keys in the mapper.V - The type of the values in the mapper.kType - The type of the keys in the mapper.mapper - The mapper to direct requests to.mapper.public final IListEnumerable<IEdge> createEdgeEnumerable(EdgeList edges)
enumerable of edges that maps the edges from the EdgeList to their original
ones.
This method is useful where algorithms yield EdgeList instances as results and the result needs to be
interpreted in terms of the OriginalGraph.
edges - The edge list.original edges for the ones in the list.public final EdgeList createEdgeList(Iterable<IEdge> edges)
EdgeList that maps the edges from the Iterable to their copied
ones.
This method is useful where algorithms require EdgeList instances as input and those edges are available as
Iterables in the OriginalGraph.
edges - The edges from the OriginalGraph.EdgeList that contains the copied edges for the ones in the enumerable.public final <V> IEdgeMap createEdgeMap(Function<IEdge,V> getter)
IEdgeMap that delegates to the provided delegate when queried for Edges in the
YGraph.
This method is useful where algorithms require IEdgeMaps as input and this can be mapped to a corresponding
dynamic callback that provides the values for the original edges.
V - The type of the values in the mapper.getter - The mapper delegate to direct read requests to.INodeMap that will delegate reads to the getter.public final <V> IEdgeMap createEdgeMap(IMapper<IEdge,V> mapper)
IEdgeMap that delegates to the provided IMapper when queried for Edges in the
YGraph.
This method is useful where algorithms require IEdgeMaps as input and this can be mapped to corresponding IMapper
instances that provide and accept the values for the original edges.
V - The type of the values in the mapper.mapper - The mapper to direct requests to.IEdgeMap that will delegate reads and writes to the mapper.public final <T> IMapper<IModelItem,T> createMapper(IDataProvider dataProvider)
IMapper that delegates to the provided IDataProvider when queried for items in the
IGraph.
This method is useful where algorithms yield IDataProviders and their values should be provided using IMapper
instances that use the original edges and the
original nodes.
T - The type of the values in the mapper.dataProvider - The provider to direct requests to.dataProvider.public final <T> IMapper<IEdge,T> createMapper(IEdgeMap edgeMap)
IMapper that delegates to the provided IEdgeMap when queried for items in the
IGraph.
This method is useful where algorithms yield IDataProviders and their values should be provided using IMapper
instances that use the original edges.
T - The type of the values in the mapper.edgeMap - The map to direct requests to.edgeMap.public final <T> IMapper<INode,T> createMapper(INodeMap nodeMap)
IMapper that delegates to the provided INodeMap when queried for items in the
IGraph.
This method is useful where algorithms yield INodeMaps and their values should be provided using IMapper
instances that use the original nodes.
T - The type of the values in the mapper.nodeMap - The map to direct requests to.nodeMap.public final IListEnumerable<INode> createNodeEnumerable(NodeList nodes)
enumerable of nodes that maps the nodes from the NodeList to their original
ones.
This method is useful where algorithms yield NodeList instances as results and the result needs to be
interpreted in terms of the OriginalGraph.
nodes - The node list.original nodes for the ones in the list.public final NodeList createNodeList(Iterable<INode> nodes)
NodeList that maps the nodes from the Iterable to their copied
ones.
This method is useful where algorithms require NodeList instances as input and those nodes are available as
Iterables in the OriginalGraph.
nodes - The nodes from the OriginalGraph.NodeList that contains the copied nodes for the ones in the enumerable.public final <V> INodeMap createNodeMap(Function<INode,V> getter)
INodeMap that delegates to the provided delegate when queried for Nodes in the
YGraph.
This method is useful where algorithms require INodeMaps as input and this can be mapped to a corresponding
dynamic callback that provides the values for the original nodes.
V - The type of the values in the mapper.getter - The mapper delegate to direct read requests to.INodeMap that will delegate reads to the getter.public final <V> INodeMap createNodeMap(IMapper<INode,V> mapper)
INodeMap that delegates to the provided IMapper when queried for Nodes in the
YGraph.
This method is useful where algorithms require INodeMaps as input and this can be mapped to corresponding IMapper
instances that provide and accept the values for the original nodes.
V - The type of the values in the mapper.mapper - The mapper to direct requests to.INodeMap that will delegate reads and writes to the mapper.public final Edge getCopiedEdge(IEdge edge)
YGraph to represent the given edge.edge - The edge for which the representation is returned.edge in YGraph.public final Node getCopiedNode(INode node)
YGraph to represent the given node.node - The node for which the representation is returned.node in YGraph.public final IEdge getOriginalEdge(Edge edge)
original IGraph that the given edge has been created for.edge - The edge for which the original instance will be returned.public final IGraph getOriginalGraph()
public final INode getOriginalNode(Node node)
original IGraph that the given node has been created for.node - The node for which the original instance will be returned.public final Graph getYGraph()