Class GraphTypeBuilder<V,​E>

  • Type Parameters:
    V - the graph vertex type
    E - the graph edge type

    public final class GraphTypeBuilder<V,​E>
    extends java.lang.Object
    A builder class for the hierarchy of Graphs that the library provides.

    The following example creates a directed graph which allows multiple (parallel) edges and self-loops:

     Graph<Integer,
         DefaultEdge> g = GraphTypeBuilder
             .<Integer, DefaultEdge> directed().allowingMultipleEdges(true).allowingSelfLoops(true)
             .edgeClass(DefaultEdge.class).buildGraph();
     
    Similarly one could get a weighted multigraph by using:
     Graph<Integer, DefaultWeightedEdge> g = GraphTypeBuilder
         .<Integer, DefaultWeightedEdge> undirected().allowingMultipleEdges(true)
         .allowingSelfLoops(false).edgeClass(DefaultWeightedEdge.class).weighted(true).buildGraph();
     

    The builder also provides the ability to construct a graph from another graph such as:

     Graph<Integer, DefaultWeightedEdge> g1 = GraphTypeBuilder
         .<Integer, DefaultWeightedEdge> undirected().allowingMultipleEdges(true)
         .allowingSelfLoops(false).edgeClass(DefaultWeightedEdge.class).weighted(true).buildGraph();
     
     Graph<Integer, DefaultWeightedEdge> g2 = GraphTypeBuilder.asGraph(g1).buildGraph();
     
    Author:
    Dimitrios Michail
    See Also:
    GraphType, GraphBuilder
    • Method Detail

      • directed

        public static <V,​E> GraphTypeBuilder<V,​E> directed()
        Create a graph type builder for a directed graph.
        Type Parameters:
        V - the graph vertex type
        E - the graph edge type
        Returns:
        the graph type builder
      • undirected

        public static <V,​E> GraphTypeBuilder<V,​E> undirected()
        Create a graph type builder for an undirected graph.
        Type Parameters:
        V - the graph vertex type
        E - the graph edge type
        Returns:
        the graph type builder
      • mixed

        public static <V,​E> GraphTypeBuilder<V,​E> mixed()
        Create a graph type builder for a mixed graph.
        Type Parameters:
        V - the graph vertex type
        E - the graph edge type
        Returns:
        the graph type builder
      • forGraphType

        public static <V,​E> GraphTypeBuilder<V,​E> forGraphType​(GraphType type)
        Create a graph type builder which will create a graph with the same type as the one provided.
        Type Parameters:
        V - the graph vertex type
        E - the graph edge type
        Parameters:
        type - the graph type
        Returns:
        the graph type builder
      • forGraph

        public static <V,​E> GraphTypeBuilder<V,​E> forGraph​(Graph<V,​E> graph)
        Create a graph type builder which will create the same graph type as the parameter graph. The new graph will use the same vertex and edge suppliers as the input graph.
        Type Parameters:
        V - the graph vertex type
        E - the graph edge type
        Parameters:
        graph - a graph
        Returns:
        a type builder
      • weighted

        public GraphTypeBuilder<V,​E> weighted​(boolean weighted)
        Set whether the graph will be weighted or not.
        Parameters:
        weighted - if true the graph will be weighted
        Returns:
        the graph type builder
      • allowingSelfLoops

        public GraphTypeBuilder<V,​E> allowingSelfLoops​(boolean allowingSelfLoops)
        Set whether the graph will allow self loops (edges with same source and target vertices).
        Parameters:
        allowingSelfLoops - if true the graph will allow self-loops
        Returns:
        the graph type builder
      • allowingMultipleEdges

        public GraphTypeBuilder<V,​E> allowingMultipleEdges​(boolean allowingMultipleEdges)
        Set whether the graph will allow multiple (parallel) edges between the same two vertices.
        Parameters:
        allowingMultipleEdges - if true the graph will allow multiple (parallel) edges
        Returns:
        the graph type builder
      • vertexSupplier

        public <V1 extends VGraphTypeBuilder<V1,​E> vertexSupplier​(java.util.function.Supplier<V1> vertexSupplier)
        Set the vertex supplier.
        Type Parameters:
        V1 - the graph vertex type
        Parameters:
        vertexSupplier - the vertex supplier to use
        Returns:
        the graph type builder
      • edgeSupplier

        public <E1 extends EGraphTypeBuilder<V,​E1> edgeSupplier​(java.util.function.Supplier<E1> edgeSupplier)
        Set the edge supplier.
        Type Parameters:
        E1 - the graph edge type
        Parameters:
        edgeSupplier - the edge supplier to use
        Returns:
        the graph type builder
      • vertexClass

        public <V1 extends VGraphTypeBuilder<V1,​E> vertexClass​(java.lang.Class<V1> vertexClass)
        Set the vertex class.
        Type Parameters:
        V1 - the graph vertex type
        Parameters:
        vertexClass - the vertex class
        Returns:
        the graph type builder
      • edgeClass

        public <E1 extends EGraphTypeBuilder<V,​E1> edgeClass​(java.lang.Class<E1> edgeClass)
        Set the edge class.
        Type Parameters:
        E1 - the graph edge type
        Parameters:
        edgeClass - the edge class
        Returns:
        the graph type builder
      • buildType

        public GraphType buildType()
        Build the graph type.
        Returns:
        a graph type
      • buildGraphBuilder

        public GraphBuilder<V,​E,​Graph<V,​E>> buildGraphBuilder()
        Build the graph and acquire a GraphBuilder in order to add vertices and edges.
        Returns:
        a graph builder
      • buildGraph

        public Graph<V,​E> buildGraph()
        Build the actual graph.
        Returns:
        the graph
        Throws:
        java.lang.UnsupportedOperationException - in case a graph type is not supported