Class HashGraph.Builder<V,E>

java.lang.Object
rgu.transport.algorithms.collections.HashGraph.Builder<V,E>
Enclosing class:
HashGraph<V,E>

public static final class HashGraph.Builder<V,E> extends Object
Builder class for HashGraph. Builder is not safe for concurrent use.
Author:
Lee A. Christie
  • Method Details

    • addVertex

      public HashGraph.Builder<V,E> addVertex(V vertex)
      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

      @SafeVarargs public final HashGraph.Builder<V,E> addVertices(V... vertices)
      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

      public HashGraph.Builder<V,E> addVertices(Collection<V> vertices)
      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

      public HashGraph.Builder<V,E> addEdge(V from, V to, E edge)
      Adds a new edge to the graph.
      Parameters:
      from - the source vertex, not null
      to - the destination vertex, not null
      edge - the edge, not null
      Returns:
      this, for chaining
      Throws:
      IllegalStateException - if already built, or the edge already exists
      NoSuchElementException - if either vertex does not exist
    • tryAddEdge

      public boolean tryAddEdge(V from, V to, E edge)
      Tries to add a new edge to the graph, and returns a boolean indicating whether it was successful.
      Parameters:
      from - the source vertex, not null
      to - the destination vertex, not null
      edge - the edge, not null
      Returns:
      true if successful, false otherwise
    • build

      public HashGraph<V,E> build()
      Builds and returns the graph.
      Returns:
      the graph
      Throws:
      IllegalStateException - if already built