Package org.anchoranalysis.core.graph
Class GraphWithPayload<V,P>
Object
GraphWithPayload<V,P>
- Type Parameters:
V
- vertex-typeP
- edge payload-type
A graph, either directed or undirected, with edges containing a payload of type
E
.- Author:
- Owen Feehan
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an edge between two vertices.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
(boolean includeEdgePayload) Describes the graph in a multi-line string.The edges in the graph, all of them, but with some edges possibly duplicated.The edges in the graph, all of them, without any duplicates.int
The number of edges in the graph.int
The number of vertices in the graph.outgoingEdgesFor
(V vertex) All outgoing edges for a given vertex.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.Creates a new graph with identical elements and structure, reusing the existing vertice and edge data objects.toString()
vertices()
The set of all vertices in the graph.
-
Constructor Details
-
GraphWithPayload
public GraphWithPayload(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
-
shallowCopy
Creates a new graph with identical elements and structure, reusing the existing vertice and edge data objects.- Returns:
- a newly created graph, with newly created vertices and edges, but reusing the
data-objects of tyoe
V
andE
.
-
vertices
The set of all vertices in the graph.- Returns:
- the set (as is used internally within the class, without any duplication).
-
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
-
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
.- Parameters:
from
- the vertex the edge joins from.to
- the vertex the edge joins to.edgePayload
- the payload for the 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.
-
edgesUnique
The edges in the graph, all of them, without any duplicates.This operation is more expensive than
edgesMaybeDuplicates()
but guarantees that no edge is repeated.- Returns:
- a newly created set containing the edges of the graph.
-
edgesMaybeDuplicates
The edges in the graph, all of them, but with some edges possibly duplicated.This operation is more cheaper than
edgesUnique()
but edges may exist twice.- Returns:
- the collection (as exists internally) of edges in the graph, with some edges may exist twice.
-
adjacentVerticesOutgoing
The vertices that are connected to a particular vertex by an outgoing edge.- Parameters:
vertex
- the vertex to find adjacent vertices for- Returns:
- a newly created
List
with all vertices to which an outgoing edge exists fromvertex
-
adjacentVerticesOutgoingStream
- Parameters:
vertex
- the vertex to find adjacent vertices for- Returns:
- all vertices to which an outgoing edge exists from
vertex
-
outgoingEdgesFor
All outgoing edges for a given vertex.- Parameters:
vertex
- the vertex- Returns:
- a collection (based on an internal data structure, unduplicated) of outgoing edges for the vertex.
-
toString
-
describe
Describes the graph in a multi-line string.- Parameters:
includeEdgePayload
- whether to show the payload of each edge- Returns:
- a multi-line string describing the graph
-