Package org.anchoranalysis.core.graph
Class GraphWithoutPayload<V>
Object
GraphWithoutPayload<V>
- Type Parameters:
V
- vertex-type
A graph, either directed or undirected, where edges contain no payload.
- Author:
- Owen Feehan
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an edge between two vertices.void
addEdges
(V from, Collection<V> toCollection) Adds edge(s) from the vertexfrom
to each element intoCollection
.void
Adds a vertex.adjacentVerticesOutgoing
(V vertex) The vertices that are connected to a particular vertex by an outgoing edge.adjacentVerticesOutgoingStream
(V vertex) boolean
containsEdge
(V from, V to) Does the graph contain a particular edge?boolean
containsVertex
(V vertex) Does the graph contain a particular vertex?describe()
Describes the graph in a multi-line string.void
mergeVertices
(V element1, V element2, V merged) Merges two existing vertices together.int
The number of edges in the graph.int
The number of vertices in the graph.void
removeEdge
(V from, V to) Remove an edge between two vertices.void
removeVertex
(V vertex) Removes a vertex and any edges connected to it.toString()
vertices()
The set of all vertices in the graph.
-
Constructor Details
-
GraphWithoutPayload
public GraphWithoutPayload(boolean undirected) Creates the graph.- Parameters:
undirected
- true if it should be an undirected graph (an edge applies in both directions), false if it should be a directed graph (an edge applies in one direction only).
-
-
Method Details
-
containsVertex
Does the graph contain a particular vertex?- Parameters:
vertex
- the vertex to check if it is contained- Returns:
- true iff the graph contains the vertex
-
containsEdge
Does the graph contain a particular edge?- Parameters:
from
- the vertex the edge emanates from.to
- the vertex the edge is connected to.- Returns:
- true iff an edge exists from
from
toto
.
-
addVertex
Adds a vertex.- Parameters:
vertex
- the vertex to add
-
removeVertex
Removes a vertex and any edges connected to it.- Parameters:
vertex
- the vertex to remove- Throws:
OperationFailedException
- if the vertex doesn't exist in the graph.
-
addEdge
Add an edge between two vertices.For an undirected graph, the directionality is irrelevant, and will achieve the same effect, whatever the order of
from
andto
.No error is reported if an edge already exists.
- Parameters:
from
- the vertex the edge joins from.to
- the vertex the edge joins to.
-
addEdges
Adds edge(s) from the vertexfrom
to each element intoCollection
.This creates as many edges as exist elements in
toCollection
, unless some such edges already exist.No error is reported if an edge already exists.
- Parameters:
from
- the vertex the edge joins from.toCollection
- the vertex the edge joins to, for each intended edge.
-
removeEdge
Remove an edge between two vertices.For an undirected graph, the directionality is irrelevant, and will achieve the same effect, whatever the order of
from
andto
.- Parameters:
from
- the vertex the edge joins from.to
- the vertex the edge joins to.
-
toString
-
adjacentVerticesOutgoing
The vertices that are connected to a particular vertex by an outgoing edge.- Parameters:
vertex
- the vertex to find adjacent vertices for.- Returns:
- all vertices to which an outgoing edge exists from
vertex
.
-
adjacentVerticesOutgoingStream
- Parameters:
vertex
- the vertex to find adjacent vertices for.- Returns:
- all vertices to which an outgoing edge exists from
vertex
.
-
mergeVertices
Merges two existing vertices together.The two existing vertices are replaced with
merged
.Existing incoming and outgoing edges for the two vertices are then connected instead to
merged
.- Parameters:
element1
- the first element to merge.element2
- the second element to merge.merged
- the merged element that replaceselement1
andelement2
.
-
numberVertices
public int numberVertices()The number of vertices in the graph.- Returns:
- the number of vertices
-
numberEdges
public int numberEdges()The number of edges in the graph.- Returns:
- the number of edges
-
vertices
The set of all vertices in the graph.- Returns:
- the set (as is used internally within the class, without any duplication).
-
describe
Describes the graph in a multi-line string.- Returns:
- a multi-line string describing the graph
-