Class HashGraph.Builder<V,E>
java.lang.Object
rgu.transport.algorithms.collections.HashGraph.Builder<V,E>
Builder class for HashGraph. Builder is not safe for concurrent use.
- Author:
- Lee A. Christie
-
Method Summary
Modifier and TypeMethodDescriptionAdds a new edge to the graph.Add a new vertex to the graph.addVertices(Collection<V> vertices) Add new vertices to the graph.final HashGraph.Builder<V, E> addVertices(V... vertices) Add new vertices to the graph.build()Builds and returns the graph.booleantryAddEdge(V from, V to, E edge) Tries to add a new edge to the graph, and returns a boolean indicating whether it was successful.
-
Method Details
-
addVertex
Add a new vertex to the graph.- Parameters:
vertex- the new vertex, not null- Returns:
- this, for chaining
- Throws:
IllegalStateException- if already built, or the vertex already exists
-
addVertices
Add new vertices to the graph. If there are any duplicate vertices, the builder is unchanged.- Parameters:
vertices- the new vertices, not null- Returns:
- this, for chaining
- Throws:
IllegalStateException- if already built, or any of the vertices already exist
-
addVertices
Add new vertices to the graph. If there are any duplicate vertices, the builder is unchanged.- Parameters:
vertices- the new vertices, not null- Returns:
- this, for chaining
- Throws:
IllegalStateException- if already built, or any of the vertices already exist
-
addEdge
Adds a new edge to the graph.- Parameters:
from- the source vertex, not nullto- the destination vertex, not nulledge- the edge, not null- Returns:
- this, for chaining
- Throws:
IllegalStateException- if already built, or the edge already existsNoSuchElementException- if either vertex does not exist
-
tryAddEdge
Tries to add a new edge to the graph, and returns a boolean indicating whether it was successful.- Parameters:
from- the source vertex, not nullto- the destination vertex, not nulledge- the edge, not null- Returns:
- true if successful, false otherwise
-
build
Builds and returns the graph.- Returns:
- the graph
- Throws:
IllegalStateException- if already built
-