V
- vertex-typeP
- edge payload-typepublic class GraphWithPayload<V,P> extends Object
E
.Constructor and Description |
---|
GraphWithPayload(boolean undirected)
Creates the graph.
|
Modifier and Type | Method and Description |
---|---|
void |
addEdge(V from,
V to,
P edgePayload)
Add an edge between two vertices.
|
void |
addVertex(V vertex)
Adds a vertex.
|
List<V> |
adjacentVerticesOutgoing(V vertex)
The vertices that are connected to a particular vertex by an outgoing edge.
|
java.util.stream.Stream<V> |
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?
|
String |
describe(boolean includeEdgePayload)
Describes the graph in a multi-line string.
|
Collection<TypedEdge<V,P>> |
edgesMaybeDuplicates()
The edges in the graph, all of them, but with some edges possibly duplicated.
|
Set<TypedEdge<V,P>> |
edgesUnique()
The edges in the graph, all of them, without any duplicates.
|
int |
numberEdges()
The number of edges in the graph.
|
int |
numberVertices()
The number of vertices in the graph.
|
Collection<TypedEdge<V,P>> |
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.
|
GraphWithPayload<V,P> |
shallowCopy()
Creates a new graph with identical elements and structure, reusing the existing vertice and
edge data objects.
|
String |
toString() |
Set<V> |
vertices()
The set of all vertices in the graph.
|
public GraphWithPayload(boolean undirected)
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).public GraphWithPayload<V,P> shallowCopy()
V
and E
.public Set<V> vertices()
public int numberVertices()
public int numberEdges()
public boolean containsVertex(V vertex)
vertex
- the vertex to check if it is containedpublic boolean containsEdge(V from, V to)
from
- the vertex the edge emanates from.to
- the vertex the edge is connected to.from
to to
.public void addVertex(V vertex)
vertex
- the vertex to addpublic void removeVertex(V vertex) throws OperationFailedException
vertex
- the vertex to removeOperationFailedException
- if the vertex doesn't exist in the graph.public void addEdge(V from, V to, P edgePayload)
For an undirected graph, the directionality is irrelevant, and will achieve the same
effect, whatever the order of from
and to
.
from
- the vertex the edge joins from.to
- the vertex the edge joins to.edgePayload
- the payload for the edge.public void removeEdge(V from, V to)
For an undirected graph, the directionality is irrelevant, and will achieve the same
effect, whatever the order of from
and to
.
from
- the vertex the edge joins from.to
- the vertex the edge joins to.public Set<TypedEdge<V,P>> edgesUnique()
This operation is more expensive than edgesMaybeDuplicates()
but guarantees that
no edge is repeated.
public Collection<TypedEdge<V,P>> edgesMaybeDuplicates()
This operation is more cheaper than edgesUnique()
but edges may exist twice.
public List<V> adjacentVerticesOutgoing(V vertex)
vertex
- the vertex to find adjacent vertices forList
with all vertices to which an outgoing edge exists from
vertex
public java.util.stream.Stream<V> adjacentVerticesOutgoingStream(V vertex)
vertex
- the vertex to find adjacent vertices forvertex
public Collection<TypedEdge<V,P>> outgoingEdgesFor(V vertex)
vertex
- the vertexpublic String describe(boolean includeEdgePayload)
includeEdgePayload
- whether to show the payload of each edgeCopyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.