Class DirectedGraph<T>
java.lang.Object
org.apache.struts2.config.providers.DirectedGraph<T>
- All Implemented Interfaces:
Iterable<T>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Given a start node, and a destination, adds an arc from the start node to the destination.boolean
Adds a new node to the graph.boolean
edgeExists
(T start, T end) Given two nodes in the graph, returns whether there is an edge from the first node to the second node.Given a node in the graph, returns an immutable view of the edges leaving that node as a set of endpoints.boolean
isEmpty()
Returns whether the graph is empty.iterator()
Returns an iterator that can traverse the nodes in the graph.void
removeEdge
(T start, T dest) Removes the edge from start to dest from the graph.int
size()
Returns the number of nodes in the graph.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
DirectedGraph
public DirectedGraph()
-
-
Method Details
-
addNode
Adds a new node to the graph. If the node already exists, this function is a no-op.- Parameters:
node
- The node to add.- Returns:
- Whether or not the node was added.
-
addEdge
Given a start node, and a destination, adds an arc from the start node to the destination. If an arc already exists, this operation is a no-op. If either endpoint does not exist in the graph, throws a NoSuchElementException.- Parameters:
start
- The start node.dest
- The destination node.- Throws:
NoSuchElementException
- If either the start or destination nodes do not exist.
-
removeEdge
Removes the edge from start to dest from the graph. If the edge does not exist, this operation is a no-op. If either endpoint does not exist, this throws a NoSuchElementException.- Parameters:
start
- The start node.dest
- The destination node.- Throws:
NoSuchElementException
- If either node is not in the graph.
-
edgeExists
Given two nodes in the graph, returns whether there is an edge from the first node to the second node. If either node does not exist in the graph, throws a NoSuchElementException.- Parameters:
start
- The start node.end
- The destination node.- Returns:
- Whether there is an edge from start to end.
- Throws:
NoSuchElementException
- If either endpoint does not exist.
-
edgesFrom
Given a node in the graph, returns an immutable view of the edges leaving that node as a set of endpoints.- Parameters:
node
- The node whose edges should be queried.- Returns:
- An immutable view of the edges leaving that node.
- Throws:
NoSuchElementException
- If the node does not exist.
-
iterator
Returns an iterator that can traverse the nodes in the graph. -
size
public int size()Returns the number of nodes in the graph.- Returns:
- The number of nodes in the graph.
-
isEmpty
public boolean isEmpty()Returns whether the graph is empty.- Returns:
- Whether the graph is empty.
-