Interface Graph
- All Known Subinterfaces:
DirectedGraph
- All Known Implementing Classes:
BasicDirectedGraph
,BasicGraph
A graph is a collection of nodes (verticies) connected by links called edges (arcs).
In most applications nodes of a graph represent the objects being modelled, and the edges represent the relationships
between the objects. An example could be a polygon coverage in which one wishes to model a boundary sharing
relationship. The following is an illustration.
In the above figure, the objects (nodes) are the polygons themselves, and the relationship (edges) between them is
boundary sharing.
However, there exists types of graphs in which the roles are reversed and the edges are the objects, and the nodes
are the relationships. An example of such a graph is the stream network shown below.
In the above figure, the objects (edges) are the stream segments and the relationship (nodes) between them is
endpoint sharing. However, if desirable one could model the second case similar to the first. The resulting graph is
shown below.
The Graph object is intended to serve as a container for a collection of nodes and edges. It does dont define or
manage the relationship among the components it contains.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Signal to indicate that a graph component does NOT meet the requirements of a query made against the graph.static final int
Signal to indicate that a graph component meets the requirements of a query against a graph and that the query should continue.static final int
Signal to indicate that a graph component meets the requirements of a query against a graph and that the query should end. -
Method Summary
Modifier and TypeMethodDescriptiongetEdges()
Returns the edges of the graph.getNodes()
Returns the nodes of the graph.getNodesOfDegree
(int n) Returns all the nodes in the graph of a specified degree.getVisitedEdges
(boolean visited) Returns all the edges in the graph that have been marked as visited or non-visited.getVisitedNodes
(boolean visited) Returns all the nodes in the graph that have been marked as visited or non-visited.queryEdges
(GraphVisitor visitor) Performs a query against the edges of the graph.queryNodes
(GraphVisitor visitor) Performs a query against the nodes of the graph.void
visitEdges
(GraphVisitor visitor) Applies the visitor pattern to the edges of the graph.void
visitNodes
(GraphVisitor visitor) Applies the visitor pattern to the nodes of the graph.
-
Field Details
-
PASS_AND_CONTINUE
static final int PASS_AND_CONTINUESignal to indicate that a graph component meets the requirements of a query against a graph and that the query should continue.- See Also:
-
PASS_AND_STOP
static final int PASS_AND_STOPSignal to indicate that a graph component meets the requirements of a query against a graph and that the query should end.- See Also:
-
FAIL_QUERY
static final int FAIL_QUERYSignal to indicate that a graph component does NOT meet the requirements of a query made against the graph.- See Also:
-
-
Method Details
-
getNodes
Collection<Node> getNodes()Returns the nodes of the graph.- Returns:
- A collection of Node objects.
- See Also:
-
getEdges
Collection<Edge> getEdges()Returns the edges of the graph.- Returns:
- A collection of Edge objects.
- See Also:
-
queryNodes
Performs a query against the nodes of the graph. Each Node object contained in the graph is passed to a GraphVisitor to determine if it meets the query criteria.- Parameters:
visitor
- Determines if node meets query criteria. Returns MEET_AND_CONTINUE to signal that the node meets the query criteria and the query should continue.
Returns MEET_AND_STOP to signal that the node meest the query criteria and the query should stop.
FAIL_QUERY to signal that the node does NOT meet the query criteria.- Returns:
- A collection of nodes that meet the query criteria.
- See Also:
-
queryEdges
Performs a query against the edges of the graph. Each Edge object contained in the graph is passed to a GraphVisitor to determine if it meets the query criteria.- Parameters:
visitor
- Determines if the meets the query criteria.
Returns MEET_AND_CONTINUE to signal that the edge meets the query criteria and the query should continue.
Returns MEET_AND_STOP to signal that the edge meest the query criteria and the query should stop.
FAIL_QUERY to signal that the edge does NOT meet the query criteria.- Returns:
- A collection of edges that meet the query criteria.
- See Also:
-
visitNodes
Applies the visitor pattern to the nodes of the graph. -
visitEdges
Applies the visitor pattern to the edges of the graph. -
getNodesOfDegree
Returns all the nodes in the graph of a specified degree. The degree of a node is the number of edges that are adjacent to the node.- Parameters:
n
- The desired degree of nodes to be returned.- Returns:
- A collection of nodes of degree n.
- See Also:
-
getVisitedNodes
Returns all the nodes in the graph that have been marked as visited or non-visited.- Parameters:
visited
- True if node is visited, false if node is unvisited.- Returns:
- List of nodes marked as visited / non-visited.
- See Also:
-
getVisitedEdges
Returns all the edges in the graph that have been marked as visited or non-visited.- Parameters:
visited
- True if edge is visited, false if edge is unvisited.- Returns:
- List of edges marked as visited / non-visited.
- See Also:
-