Class AbstractGraphBuilder<V,E,G extends Graph<V,E>,B extends AbstractGraphBuilder<V,E,G,B>>

java.lang.Object
org.jgrapht.graph.builder.AbstractGraphBuilder<V,E,G,B>
Type Parameters:
V - the graph vertex type
E - the graph edge type
G - type of the resulting graph
B - type of this builder
Direct Known Subclasses:
GraphBuilder

public abstract class AbstractGraphBuilder<V,E,G extends Graph<V,E>,B extends AbstractGraphBuilder<V,E,G,B>> extends Object
Base class for builders of Graph
Author:
Andrew Chen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final G
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a builder based on baseGraph.
  • Method Summary

    Modifier and Type
    Method
    Description
    addEdge(V source, V target)
    Adds an edge to the graph being built.
    addEdge(V source, V target, double weight)
    Adds an weighted edge to the graph being built.
    addEdge(V source, V target, E edge)
    Adds the specified edge to the graph being built.
    addEdge(V source, V target, E edge, double weight)
    Adds the specified weighted edge to the graph being built.
    final B
    addEdgeChain(V first, V second, V... rest)
    Adds a chain of edges to the graph being built.
    addGraph(Graph<? extends V,? extends E> sourceGraph)
    Adds all the vertices and all the edges of the sourceGraph to the graph being built.
    addVertex(V vertex)
    Adds vertex to the graph being built.
    final B
    addVertices(V... vertices)
    Adds each vertex of vertices to the graph being built.
    Build the graph.
    Build an unmodifiable version graph.
    removeEdge(E edge)
    Removes the specified edge from the graph.
    removeEdge(V source, V target)
    Removes an edge going from source vertex to target vertex from the graph being built, if such vertices and such edge exist in the graph.
    removeVertex(V vertex)
    Removes vertex from the graph being built, if such vertex exist in graph.
    final B
    removeVertices(V... vertices)
    Removes each vertex of vertices from the graph being built, if such vertices exist in graph.
    protected abstract B
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • graph

      protected final G extends Graph<V,E> graph
  • Constructor Details

    • AbstractGraphBuilder

      public AbstractGraphBuilder(G baseGraph)
      Creates a builder based on baseGraph. baseGraph must be mutable.
      Parameters:
      baseGraph - the graph object to base building on
  • Method Details

    • self

      protected abstract B self()
      Returns:
      the this object.
    • addVertex

      public B addVertex(V vertex)
      Adds vertex to the graph being built.
      Parameters:
      vertex - the vertex to add
      Returns:
      this builder object
      See Also:
    • addVertices

      @SafeVarargs public final B addVertices(V... vertices)
      Adds each vertex of vertices to the graph being built.
      Parameters:
      vertices - the vertices to add
      Returns:
      this builder object
      See Also:
    • addEdge

      public B addEdge(V source, V target)
      Adds an edge to the graph being built. The source and target vertices are added to the graph, if not already included.
      Parameters:
      source - source vertex of the edge.
      target - target vertex of the edge.
      Returns:
      this builder object
      See Also:
    • addEdge

      public B addEdge(V source, V target, E edge)
      Adds the specified edge to the graph being built. The source and target vertices are added to the graph, if not already included.
      Parameters:
      source - source vertex of the edge.
      target - target vertex of the edge.
      edge - edge to be added to this graph.
      Returns:
      this builder object
      See Also:
    • addEdgeChain

      @SafeVarargs public final B addEdgeChain(V first, V second, V... rest)
      Adds a chain of edges to the graph being built. The vertices are added to the graph, if not already included.
      Parameters:
      first - the first vertex
      second - the second vertex
      rest - the remaining vertices
      Returns:
      this builder object
      See Also:
    • addGraph

      public B addGraph(Graph<? extends V,? extends E> sourceGraph)
      Adds all the vertices and all the edges of the sourceGraph to the graph being built.
      Parameters:
      sourceGraph - the source graph
      Returns:
      this builder object
      See Also:
    • removeVertex

      public B removeVertex(V vertex)
      Removes vertex from the graph being built, if such vertex exist in graph.
      Parameters:
      vertex - the vertex to remove
      Returns:
      this builder object
      See Also:
    • removeVertices

      @SafeVarargs public final B removeVertices(V... vertices)
      Removes each vertex of vertices from the graph being built, if such vertices exist in graph.
      Parameters:
      vertices - the vertices to remove
      Returns:
      this builder object
      See Also:
    • removeEdge

      public B removeEdge(V source, V target)
      Removes an edge going from source vertex to target vertex from the graph being built, if such vertices and such edge exist in the graph.
      Parameters:
      source - source vertex of the edge.
      target - target vertex of the edge.
      Returns:
      this builder object
      See Also:
    • removeEdge

      public B removeEdge(E edge)
      Removes the specified edge from the graph. Removes the specified edge from this graph if it is present.
      Parameters:
      edge - edge to be removed from this graph, if present.
      Returns:
      this builder object
      See Also:
    • addEdge

      public B addEdge(V source, V target, double weight)
      Adds an weighted edge to the graph being built. The source and target vertices are added to the graph, if not already included.
      Parameters:
      source - source vertex of the edge.
      target - target vertex of the edge.
      weight - weight of the edge.
      Returns:
      this builder object
      See Also:
    • addEdge

      public B addEdge(V source, V target, E edge, double weight)
      Adds the specified weighted edge to the graph being built. The source and target vertices are added to the graph, if not already included.
      Parameters:
      source - source vertex of the edge.
      target - target vertex of the edge.
      edge - edge to be added to this graph.
      weight - weight of the edge.
      Returns:
      this builder object
      See Also:
    • build

      public G build()
      Build the graph. Calling any method (including this method) on this builder object after calling this method is undefined behaviour.
      Returns:
      the built graph.
    • buildAsUnmodifiable

      public Graph<V,E> buildAsUnmodifiable()
      Build an unmodifiable version graph. Calling any method (including this method) on this builder object after calling this method is undefined behaviour.
      Returns:
      the built unmodifiable graph.
      See Also: