Interface IntGraphBuilder

    • Method Detail

      • addVertex

        void addVertex​(int vertex)
        Add a new vertex to the built graph.

        Vertices must be non negative integers.

        If there is a vertex builder, namely if vertexBuilder() does not return null, the method addVertexInt() can be used, which uses the vertex builder to create the new vertex object instead of requiring the user to provide it.

        Parameters:
        vertex - new vertex
        Throws:
        IllegalArgumentException - if vertex is already in the built graph, or if vertex is negative, as negative identifiers are not allowed
      • addVertexInt

        default int addVertexInt()
        Add a new vertex to the built graph, using the vertex builder.

        Unlike addVertex(int) in which the vertex is provided by the user, this method uses the vertex builder obtained by vertexBuilder() to create the new vertex and adds it to the graph.

        This method is equivalent to:

         
         int vertex = vertexBuilder().build(vertices());
         addVertex(vertex);
         return vertex;
         
        Returns:
        the new vertex
        Throws:
        UnsupportedOperationException - if the builder does not have a vertex builder, namely if vertexBuilder() returns null
      • addEdge

        void addEdge​(int source,
                     int target,
                     int edge)
        Add a new edge to the built graph.

        If the built graph does not support self or parallel edges and the added edge is such edge, an exception will not be thrown. The edges are validated only when the graph is built, and an exception will be thrown only then.

        Edges must be non negative integers.

        If there is an edge builder, namely if edgeBuilder() does not return null, the method addEdge(int, int) can be used, which uses the edge builder to create the new edge object instead of requiring the user to provide it.

        Parameters:
        source - a source vertex
        target - a target vertex
        edge - a new edge identifier
        Throws:
        IllegalArgumentException - if edge is already in the graph or if it is negative, as negative identifiers are not allowed
        NoSuchVertexException - if source or target are not valid vertices identifiers
      • addEdge

        @Deprecated
        default void addEdge​(Integer source,
                             Integer target,
                             Integer edge)
        Deprecated.
        Please use addEdge(int, int, int) instead to avoid un/boxing.
        Add a new edge to the built graph.

        If the built graph does not support self or parallel edges and the added edge is such edge, an exception will not be thrown. The edges are validated only when the graph is built, and an exception will be thrown only then.

        An edge can be any non null hashable object, namely it must implement the Object.hashCode() and Object.equals(Object) methods. Duplicate edges are not allowed.

        If there is an edge builder, namely if GraphBuilder.edgeBuilder() does not return null, the method GraphBuilder.addEdge(Object, Object) can be used, which uses the edge builder to create the new edge object instead of requiring the user to provide it.

        Specified by:
        addEdge in interface GraphBuilder<Integer,​Integer>
        Parameters:
        source - a source vertex
        target - a target vertex
        edge - a new edge identifier
      • addEdge

        default int addEdge​(int source,
                            int target)
        Add a new edge to the built graph, using the edge builder.

        Unlike addEdge(int, int, int) in which the edge (identifier) is provided by the user, this method uses the edge builder obtained by edgeBuilder() to create the new edge object and adds it to the graph.

        If the graph does not support self or parallel edges and the added edge is such edge, an exception will not be thrown. The edges are validated only when the graph is built, and an exception will be thrown only then.

        This method is equivalent to:

         
         int edge = edgeBuilder().build(edges());
         addEdge(source, target, edge);
         return edge;
         
        Parameters:
        source - a source vertex
        target - a target vertex
        Returns:
        the new edge
        Throws:
        UnsupportedOperationException - if the builder does not have an edge builder, namely if edgeBuilder() returns null
        NoSuchVertexException - if source or target are not valid vertices identifiers
      • addEdge

        @Deprecated
        default Integer addEdge​(Integer source,
                                Integer target)
        Deprecated.
        Please use addEdge(int, int) instead to avoid un/boxing.
        Add a new edge to the built graph, using the edge builder.

        Unlike GraphBuilder.addEdge(Object, Object, Object) in which the edge (identifier) is provided by the user, this method uses the edge builder obtained by GraphBuilder.edgeBuilder() to create the new edge object and adds it to the graph.

        If the built graph does not support self or parallel edges and the added edge is such edge, an exception will not be thrown. The edges are validated only when the graph is built, and an exception will be thrown only then.

        This method is equivalent to:

         
         E edge = edgeBuilder().build(edges());
         addEdge(source, target, edge);
         return edge;
         
        Specified by:
        addEdge in interface GraphBuilder<Integer,​Integer>
        Parameters:
        source - a source vertex
        target - a target vertex
        Returns:
        the new edge
      • verticesWeights

        <T,​WeightsT extends Weights<Integer,​T>> WeightsT verticesWeights​(String key)
        Get the vertices weights of some key.

        See Weights for a complete documentation of the weights containers.

        The return object is always some sub class of IWeights, such as IWeightsInt or IWeightsDouble.

        Specified by:
        verticesWeights in interface GraphBuilder<Integer,​Integer>
        Type Parameters:
        T - The weight data type
        WeightsT - the weights container, used to avoid casts of containers of primitive types such as WeightsInt, WeightsDouble ect.
        Parameters:
        key - key of the weights
        Returns:
        vertices weights of the key, or null if no container found with the specified key
      • edgesWeights

        <T,​WeightsT extends Weights<Integer,​T>> WeightsT edgesWeights​(String key)
        Get the edges weights of some key.

        See Weights for a complete documentation of the weights containers.

        The return object is always some sub class of IWeights, such as IWeightsInt or IWeightsDouble.

        Specified by:
        edgesWeights in interface GraphBuilder<Integer,​Integer>
        Type Parameters:
        T - The weight data type
        WeightsT - the weights container, used to avoid casts of containers of primitive types such as WeightsInt, WeightsDouble ect.
        Parameters:
        key - key of the weights
        Returns:
        edges weights of the key, or null if no container found with the specified key
      • build

        IntGraph build()
        Description copied from interface: GraphBuilder
        Build a new immutable graph with the builder vertices and edges.

        Before the graph is built, the edges are validated. If the graph does not support self or parallel edges and such edges were added to the builder, an exception will be thrown.

        Specified by:
        build in interface GraphBuilder<Integer,​Integer>
        Returns:
        a new immutable graph with the vertices and edges that were added to the builder.
      • buildMutable

        IntGraph buildMutable()
        Description copied from interface: GraphBuilder
        Build a new mutable graph with the builder vertices and edges.

        Before the graph is built, the edges are validated. If the graph does not support self or parallel edges and such edges were added to the builder, an exception will be thrown.

        Specified by:
        buildMutable in interface GraphBuilder<Integer,​Integer>
        Returns:
        a new mutable graph with the vertices and edges that were added to the builder.
      • undirected

        static IntGraphBuilder undirected()
        Create a new builder that builds undirected graphs.

        The graphs built by this builder will have the same default capabilities as IntGraphFactory, namely they will not support self edges and will support parallel edges. See the factory documentation for more information.

        For more options to instantiate a builder, create a new IntGraphFactory and use one of its newBuilder methods.

        Returns:
        a new empty builder for undirected graphs
      • directed

        static IntGraphBuilder directed()
        Create a new builder that builds directed int graphs.

        The graphs built by this builder will have the same default capabilities as IntGraphFactory, namely they will not support self edges and will support parallel edges. See the factory documentation for more information.

        For more options to instantiate a builder, create a new IntGraphFactory and use one of its newBuilder methods.

        Returns:
        a new empty builder for directed graphs
      • newInstance

        static IntGraphBuilder newInstance​(boolean directed)
        Create a new builder that builds un/directed int graphs.

        The graphs built by this builder will have the same default capabilities as IntGraphFactory, namely they will not support self edges and will support parallel edges. See the factory documentation for more information.

        For more options to instantiate a builder, create a new IntGraphFactory and use one of its newBuilder methods.

        Parameters:
        directed - if true, the new builder will build directed graphs, otherwise it will build undirected graphs
        Returns:
        a new empty builder for un/directed graphs
      • newCopyOf

        static IntGraphBuilder newCopyOf​(Graph<Integer,​Integer> g)
        Create a new builder initialized with an existing graph vertices and edges, without copying the weights.

        If the given graph is directed, the new builder will build directed graphs, and similarly for undirected graphs.

        For more options to instantiate a builder, create a new IntGraphFactory and use one of its newBuilder methods.

        Parameters:
        g - a graph
        Returns:
        a builder initialized with the given graph vertices and edges, without the original graph vertices/edges weights.
      • newCopyOf

        static IntGraphBuilder newCopyOf​(Graph<Integer,​Integer> g,
                                         boolean copyVerticesWeights,
                                         boolean copyEdgesWeights)
        Create a new builder initialized with an existing graph vertices and edges, with/without copying the weights.

        If the given graph is directed, the new builder will build directed graphs, and similarly for undirected graphs.

        For more options to instantiate a builder, create a new IntGraphFactory and use one of its newBuilder methods.

        Parameters:
        g - a graph
        copyVerticesWeights - if true, the weights of the vertices will be copied from the graph to the builder
        copyEdgesWeights - if true, the weights of the edges will be copied from the graph to the builder
        Returns:
        a builder initialized with the given graph vertices and edges, with/without the original graph vertices/edges weights.