Package cdc.graphs
Interface GraphAdapter<N,E>
-
- Type Parameters:
N- Node class.E- Edge class.
public interface GraphAdapter<N,E>Interface giving access to a heavy graph, where nodes and edges are represented as objects.Graph algorithms can be built using this interface without forcing a graph implementation to implement this interface.
- Author:
- Damien Carbonne
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleancontainsEdge(E edge)Returnstrueif an edge belongs to this graph.booleancontainsNode(N node)Returnstrueif a node belongs to this graph.default Set<N>getConnectedNodes(N node)Returns a set of all nodes that are connected to a node.default Set<N>getConnectedNodes(N node, EdgeDirection direction)Returns an Iterable of edges attached to a node in a given direction.default NodeConnectivitygetConnectivity(N node)Returns the connectivity of a node.Iterable<? extends E>getEdges()default Iterable<? extends E>getEdges(Predicate<? super E> predicate)default Iterable<? extends E>getEdges(N node)Iterable<? extends E>getEdges(N node, EdgeDirection direction)Returns an Iterable of edges attached to a node in a given direction.default Iterable<? extends E>getEdges(N node, EdgeDirection direction, Predicate<? super E> predicate)Returns an Iterable of edges attached to a node in a given direction and matching a predicate.default Iterable<? extends E>getEdges(N node, Predicate<? super E> predicate)default intgetEdgesCount()default intgetEdgesCount(N node)Returns the number of edges attached to a node, in any direction.default intgetEdgesCount(N node, EdgeDirection direction)Returns the number of edges attached to a node, in one or any direction.default Stream<? extends E>getEdgesStream()default Stream<? extends E>getEdgesStream(N node)default Stream<? extends E>getEdgesStream(N node, EdgeDirection direction)default Set<N>getLeaves()Iterable<? extends N>getNodes()default Iterable<? extends N>getNodes(Predicate<? super N> predicate)Return an Iterable of all nodes that match a predicate.default intgetNodesCount()default Stream<? extends N>getNodesStream()default Set<N>getRoots()NgetTip(E edge, EdgeTip tip)Returns a tip of an edge.default booleanhasEdge(N source, N target)Returnstruewhen there is an edge between a source node and target node.default booleanhasEdges()default booleanhasEdges(N node)Returnstruewhen there are edges attached to a node, in any direction.default booleanhasEdges(N node, EdgeDirection direction)Returnstruewhen there are edges attached to a node, in one or any direction.default booleanhasNodes()default booleanisLeaf(N node)Returntrueif a node is a leaf: It has no outgoing edges.default booleanisRoot(N node)Returnstruewhen a node is a root: It has no ingoing edges.
-
-
-
Method Detail
-
getNodes
default Iterable<? extends N> getNodes(Predicate<? super N> predicate)
Return an Iterable of all nodes that match a predicate.- Parameters:
predicate- The predicate.- Returns:
- an Iterable of all nodes that match
predicate.
-
getNodesCount
default int getNodesCount()
- Returns:
- The number of nodes in the graph.
-
hasNodes
default boolean hasNodes()
- Returns:
trueif the graph has nodes.
-
containsNode
boolean containsNode(N node)
Returnstrueif a node belongs to this graph.- Parameters:
node- The node.- Returns:
trueifnodeis member of this graph.
-
getEdges
default Iterable<? extends E> getEdges(Predicate<? super E> predicate)
- Parameters:
predicate- The predicate.- Returns:
- an Iterable of all edges that match
predicate.
-
getEdgesCount
default int getEdgesCount()
- Returns:
- The number of edges in the graph.
-
hasEdges
default boolean hasEdges()
- Returns:
trueif the graph has edges.
-
containsEdge
boolean containsEdge(E edge)
Returnstrueif an edge belongs to this graph.- Parameters:
edge- The edge.- Returns:
trueifedgeis member of graph.
-
getEdges
Iterable<? extends E> getEdges(N node, EdgeDirection direction)
Returns an Iterable of edges attached to a node in a given direction.- Parameters:
node- The node. MUST NOT benull.direction- The direction. MAY benull. Ifnull, then all edges are returned.- Returns:
- An Iterable of edges attached to
nodeindirection.
-
getEdges
default Iterable<? extends E> getEdges(N node, EdgeDirection direction, Predicate<? super E> predicate)
Returns an Iterable of edges attached to a node in a given direction and matching a predicate.- Parameters:
node- The node. MUST NOT benull.direction- The direction. MAY benull. Ifnull, then all edges are returned.predicate- The predicate to filter edges.- Returns:
- An Iterable of edges attached to
nodeindirectionand matchingpredicate.
-
getConnectedNodes
default Set<N> getConnectedNodes(N node, EdgeDirection direction)
Returns an Iterable of edges attached to a node in a given direction.- Parameters:
node- The node. MUST NOT benull.direction- The direction. MAY benull.- Returns:
- A set of all nodes connected to
nodeindirection.
-
getConnectedNodes
default Set<N> getConnectedNodes(N node)
Returns a set of all nodes that are connected to a node.- Parameters:
node- The node.- Returns:
- A set of all nodes that are connected to
node.
-
getEdgesStream
default Stream<? extends E> getEdgesStream(N node, EdgeDirection direction)
-
getEdges
default Iterable<? extends E> getEdges(N node)
- Parameters:
node- The node.- Returns:
- An Iterable of all edges attached to
node.
-
getEdges
default Iterable<? extends E> getEdges(N node, Predicate<? super E> predicate)
- Parameters:
node- The node.predicate- The predicate.- Returns:
- An Iterable of all edges attached to
nodeand that matchpredicate.
-
getEdgesCount
default int getEdgesCount(N node, EdgeDirection direction)
Returns the number of edges attached to a node, in one or any direction.- Parameters:
node- The node.direction- The optional direction. MAY benullto indicate that direction does not matter.- Returns:
- The number of edges attached to
node, in one (if notnull) or any (ifnull)direction.
-
getEdgesCount
default int getEdgesCount(N node)
Returns the number of edges attached to a node, in any direction.- Parameters:
node- The node.- Returns:
- The number of edges attached to
node, in any direction.
-
hasEdges
default boolean hasEdges(N node, EdgeDirection direction)
Returnstruewhen there are edges attached to a node, in one or any direction.- Parameters:
node- The node.direction- The optional direction. MAY benullto indicate that direction does not matter.- Returns:
truewhen there are edges attached tonode, in one (if notnull) or any (ifnull)direction.
-
hasEdges
default boolean hasEdges(N node)
Returnstruewhen there are edges attached to a node, in any direction.- Parameters:
node- The node.- Returns:
truewhen there are edges attached tonode, in any direction.
-
getTip
N getTip(E edge, EdgeTip tip)
Returns a tip of an edge.- Parameters:
edge- The edge. MUST NOT benull.tip- The tip. MUST NOT benull.- Returns:
- The node attached to edge for tip.
-
isRoot
default boolean isRoot(N node)
Returnstruewhen a node is a root: It has no ingoing edges.- Parameters:
node- The node.- Returns:
truewhen node is a root.
-
isLeaf
default boolean isLeaf(N node)
Returntrueif a node is a leaf: It has no outgoing edges.- Parameters:
node- The node.- Returns:
truewhen node is a leaf.
-
getConnectivity
default NodeConnectivity getConnectivity(N node)
Returns the connectivity of a node.- Parameters:
node- The node- Returns:
- The connectivity of
node.
-
-