V
- vertex-typepublic class GraphWithoutPayload<V> extends Object
Constructor and Description |
---|
GraphWithoutPayload(boolean undirected)
Creates the graph.
|
Modifier and Type | Method and Description |
---|---|
void |
addEdge(V from,
V to)
Add an edge between two vertices.
|
void |
addEdges(V from,
Collection<V> toCollection)
Adds edge(s) from the vertex
from to each element in toCollection . |
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()
Describes the graph in a multi-line string.
|
void |
mergeVertices(V element1,
V element2,
V merged)
Merges two existing vertices together.
|
int |
numberEdges()
The number of edges in the graph.
|
int |
numberVertices()
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.
|
String |
toString() |
Set<V> |
vertices()
The set of all vertices in the graph.
|
public GraphWithoutPayload(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 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)
For an undirected graph, the directionality is irrelevant, and will achieve the same
effect, whatever the order of from
and to
.
No error is reported if an edge already exists.
from
- the vertex the edge joins from.to
- the vertex the edge joins to.public void addEdges(V from, Collection<V> toCollection)
from
to each element in toCollection
.
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.
from
- the vertex the edge joins from.toCollection
- the vertex the edge joins to, for each intended 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 List<V> adjacentVerticesOutgoing(V vertex)
vertex
- the vertex to find adjacent vertices for.vertex
.public java.util.stream.Stream<V> adjacentVerticesOutgoingStream(V vertex)
vertex
- the vertex to find adjacent vertices for.vertex
.public void mergeVertices(V element1, V element2, V merged)
The two existing vertices are replaced with merged
.
Existing incoming and outgoing edges for the two vertices are then connected instead to
merged
.
element1
- the first element to merge.element2
- the second element to merge.merged
- the merged element that replaces element1
and element2
.public int numberVertices()
public int numberEdges()
public Set<V> vertices()
public String describe()
Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.