public class Graph<N,E> extends Object implements Serializable
| 限定符和类型 | 方法和说明 |
|---|---|
List<Graph<N,E>> |
components()
Finds all connected components in a graph and returns an array of these components.
|
int |
edgeCount()
Returns the number of edges in the graph.
|
Graph<N,E> |
filterNodes(Predicate<String> filter) |
List<List<String>> |
findCycles()
Find cycles.
|
Collection<String> |
getChildren(String nodeId) |
E |
getEdge(Edge edge) |
E |
getEdge(String sourceId,
String targetId) |
E |
getEdge(String sourceId,
String targetId,
String name)
get edge
|
Collection<Edge> |
getEdges()
Returns the Edge for each getEdge in the graph.
|
N |
getNode(String nodeId) |
Collection<String> |
getNodes()
Get node
|
String |
getParent(String nodeId) |
Set<String> |
getSinks()
Returns those node in the graph that have no out-edge.
|
Set<String> |
getSources()
Returns those node in the graph that have no in-edge.
|
boolean |
hasEdge(Edge edge) |
boolean |
hasEdge(String sourceId,
String targetId) |
boolean |
hasEdge(String sourceId,
String targetId,
String name)
exist edge
|
boolean |
hasNode(String id)
Returns true if the graph has a node with the id.
|
Collection<Edge> |
inEdges(String nodeId) |
Collection<Edge> |
inEdges(String nodeId,
String sourceId)
Return all edge that point to the node v.
|
boolean |
isAcyclic()
This method returns true if the graph has no cycles and returns false if it does.
|
boolean |
isCompound() |
boolean |
isDirected() |
boolean |
isLeaf(String nodeId) |
boolean |
isMultiGraph() |
Collection<String> |
neighbors(String nodeId) |
int |
nodeCount()
Returns the number of node in the graph.
|
Collection<Edge> |
nodeEdges(String nodeId) |
Collection<Edge> |
nodeEdges(String nodeId,
String connectedNodeId)
Returns all edgeLabels to or from node nodeId regardless of direction.
|
Collection<Edge> |
outEdges(String nodeId) |
Collection<Edge> |
outEdges(String nodeId,
String targetId)
Return all edge that are pointed at by node v.
|
Collection<String> |
predecessors(String nodeId) |
Graph<N,E> |
removeEdge(Edge edge)
remove edge
|
Graph<N,E> |
removeEdge(String sourceId,
String targetId)
remove edge
|
Graph<N,E> |
removeEdge(String sourceId,
String targetId,
String name)
remove edge
|
Graph<N,E> |
removeNode(String id)
Remove the node with the id in the graph or do nothing if the node is not in the graph.
|
void |
setCompound(boolean compound) |
void |
setDirected(boolean directed) |
Graph<N,E> |
setEdge(Edge edge)
add new edge
|
Graph<N,E> |
setEdge(Edge edge,
E e)
add new edge
|
Graph<N,E> |
setEdge(String sourceId,
String targetId)
add edge
|
Graph<N,E> |
setEdge(String sourceId,
String targetId,
E e)
add edge
|
Graph<N,E> |
setEdge(String sourceId,
String targetId,
E e,
String name)
add new edge
|
void |
setMultiGraph(boolean multiGraph) |
Graph<N,E> |
setNode(String id)
Creates or updates the value for the node in the graph.
|
Graph<N,E> |
setNode(String id,
N n)
Creates or updates the value for the node in the graph.
|
Graph<N,E> |
setNodes(Collection<String> nodes)
Creates or updates the value for the nodes in the graph.
|
Graph<N,E> |
setNodes(Collection<String> nodes,
N n)
Creates or updates the value for the nodes in the graph.
|
Graph<N,E> |
setParent(String nodeId,
String parentId) |
Graph<N,E> |
setPath(Collection<String> path)
add multi edge by path
|
Graph<N,E> |
setPath(Collection<String> path,
E e)
add multi edge by node id's
|
Graph<N,E> |
setPath(String... nodeId)
add multi edge by node id's
|
Collection<String> |
successors(String nodeId) |
List<List<String>> |
tarjan()
This function is an implementation of Tarjan's algorithm which finds all strongly connected components in the directed graph g.
|
List<String> |
topsort()
An implementation of topological sorting (https://en.wikipedia.org/wiki/Topological_sorting).
|
public Graph()
public Graph(boolean directed,
boolean multigraph,
boolean compound)
public int nodeCount()
public Collection<String> getNodes()
public Set<String> getSources()
public Set<String> getSinks()
public Graph<N,E> setNode(String id)
id - node idpublic Graph<N,E> setNode(String id, N n)
id - node idn - node datapublic Graph<N,E> setNodes(Collection<String> nodes)
nodes - add all nodepublic Graph<N,E> setNodes(Collection<String> nodes, N n)
nodes - add all noden - data for nodepublic boolean hasNode(String id)
id - node idpublic Graph<N,E> removeNode(String id)
id - node idpublic int edgeCount()
public Collection<Edge> getEdges()
public E getEdge(String sourceId, String targetId)
sourceId - source node idtargetId - target node idpublic E getEdge(String sourceId, String targetId, String name)
sourceId - source node idtargetId - target node idname - edge namepublic Graph<N,E> setEdge(String sourceId, String targetId)
sourceId - source node idtargetId - target node idpublic Graph<N,E> setEdge(String sourceId, String targetId, E e)
sourceId - source node idtargetId - target node ide - edge datapublic Graph<N,E> setEdge(Edge edge, E e)
edge - edgee - edge datapublic Graph<N,E> setEdge(String sourceId, String targetId, E e, String name)
sourceId - source node idtargetId - target ndoe ide - edge dataname - edge namepublic boolean hasEdge(Edge edge)
public boolean hasEdge(String sourceId, String targetId, String name)
sourceId - source node idtargetId - target node idname - edge namepublic Graph<N,E> removeEdge(String sourceId, String targetId)
sourceId - source node idtargetId - target node idpublic Graph<N,E> removeEdge(String sourceId, String targetId, String name)
sourceId - source node idtargetId - target node idname - edge namepublic Graph<N,E> setPath(Collection<String> path)
path - node id collectionpublic Graph<N,E> setPath(String... nodeId)
nodeId - node idpublic Graph<N,E> setPath(Collection<String> path, E e)
path - node id collectione - edge datapublic Collection<Edge> inEdges(String nodeId)
public Collection<Edge> inEdges(String nodeId, String sourceId)
nodeId - node idsourceId - Optionally filterspublic Collection<Edge> outEdges(String nodeId)
public Collection<Edge> outEdges(String nodeId, String targetId)
nodeId - node idtargetId - Optionally filterspublic Collection<Edge> nodeEdges(String nodeId)
public Collection<Edge> nodeEdges(String nodeId, String connectedNodeId)
nodeId - node idconnectedNodeId - Optionally filterspublic Collection<String> predecessors(String nodeId)
nodeId - node idpublic Collection<String> successors(String nodeId)
nodeId - node idpublic Collection<String> neighbors(String nodeId)
nodeId - node idpublic Graph<N,E> setParent(String nodeId, String parentId)
nodeId - node idparentId - parent node idpublic Collection<String> getChildren(String nodeId)
nodeId - node idpublic Graph<N,E> filterNodes(Predicate<String> filter)
filter - node filterpublic boolean isLeaf(String nodeId)
nodeId - node idpublic boolean isDirected()
public void setDirected(boolean directed)
directed - set for field directedpublic boolean isMultiGraph()
public void setMultiGraph(boolean multiGraph)
multiGraph - set for field multiGraphpublic boolean isCompound()
public void setCompound(boolean compound)
compound - set for field compoundpublic List<Graph<N,E>> components()
public List<List<String>> tarjan()
public List<String> topsort()
public boolean isAcyclic()
Copyright © 2024. All rights reserved.