Class AbstractGraphBuilder<V,​E,​G extends Graph<V,​E>,​B extends 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 java.lang.Object
    Base class for builders of Graph
    Author:
    Andrew Chen
    • Field Summary

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

      Constructors 
      Constructor Description
      AbstractGraphBuilder​(G baseGraph)
      Creates a builder based on baseGraph.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      B addEdge​(V source, V target)
      Adds an edge to the graph being built.
      B addEdge​(V source, V target, double weight)
      Adds an weighted edge to the graph being built.
      B addEdge​(V source, V target, E edge)
      Adds the specified edge to the graph being built.
      B addEdge​(V source, V target, E edge, double weight)
      Adds the specified weighted edge to the graph being built.
      B addEdgeChain​(V first, V second, V... rest)
      Adds a chain of edges to the graph being built.
      B addGraph​(Graph<? extends V,​? extends E> sourceGraph)
      Adds all the vertices and all the edges of the sourceGraph to the graph being built.
      B addVertex​(V vertex)
      Adds vertex to the graph being built.
      B addVertices​(V... vertices)
      Adds each vertex of vertices to the graph being built.
      G build()
      Build the graph.
      Graph<V,​E> buildAsUnmodifiable()
      Build an unmodifiable version graph.
      B removeEdge​(E edge)
      Removes the specified edge from the graph.
      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.
      B removeVertex​(V vertex)
      Removes vertex from the graph being built, if such vertex exist in graph.
      B removeVertices​(V... vertices)
      Removes each vertex of vertices from the graph being built, if such vertices exist in graph.
      protected abstract B self()  
      • Methods inherited from class java.lang.Object

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

      • graph

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

      • 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 Detail

      • 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:
        Graph.addVertex(Object)
      • 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:
        addVertex(Object)
      • 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:
        Graphs.addEdgeWithVertices(Graph, Object, Object)
      • 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:
        Graph.addEdge(Object, Object, Object)
      • 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:
        addEdge(Object, Object)
      • 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:
        Graphs.addGraph(Graph, Graph)
      • 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:
        Graph.removeVertex(Object)
      • 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:
        removeVertex(Object)
      • 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:
        Graph.removeVertex(Object)
      • 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:
        Graph.removeEdge(Object)
      • 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:
        Graphs.addEdgeWithVertices(Graph, Object, Object, double)
      • 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:
        Graph.addEdge(Object, Object, Object), Graph.setEdgeWeight(Object, double)
      • 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:
        build()