Class JGraphTAdapter<V,​E>

  • Type Parameters:
    V - the vertices type
    E - the edges type
    All Implemented Interfaces:
    Graph<V,​E>

    public class JGraphTAdapter<V,​E>
    extends AbstractGraph<V,​E>
    An adapter from JGAlgo graph to JGraphT graph.

    The adapter is constructed with a JGAlgo graph and implements the JGraphT graph interface, and can be used with any JGraphT algorithm. The adapter is a live view, so any change in the JGraphT graph is reflected in the JGAlgo graph and vice versa, but the underlying JGAlgo graph should not be modified directly.

    The GraphType of the adapter determined by the capabilities of the underlying JGAlgo graph (see Graph.isDirected(), Graph.isAllowParallelEdges(), Graph.isAllowSelfEdges()). Wether the adapter is weighted or not is determined in the constructor by passing the edge weight key, see Graph.edgesWeights(String). Although JGAlgo graphs support multiple types of weights, both for vertices and edges, JGraphT graphs support only one double weight type, for edges.

    For adapting the other way around, from JGraphT to JGAlgo, see JGraphTWrapper.

    Author:
    Barak Ugav
    See Also:
    Graph, Graph, JGraphTWrapper
    • Constructor Detail

      • JGraphTAdapter

        public JGraphTAdapter​(Graph<V,​E> graph)
        Constructs a new unweighted adapter from the given JGAlgo graph.
        Parameters:
        graph - the JGAlgo graph
      • JGraphTAdapter

        public JGraphTAdapter​(Graph<V,​E> graph,
                              String edgeWeightKey)
        Constructs a new adapter from the given JGAlgo graph, optionally weighted.
        Parameters:
        graph - the JGAlgo graph
        edgeWeightKey - the edge weight key of the double weights of the JGAlgo graph (see Graph.edgesWeights(String)), or null for unweighted
        Throws:
        IllegalArgumentException - if the edge weight key is not null and it is not found in the JGAlgo graph
    • Method Detail

      • setVertexSupplier

        public void setVertexSupplier​(Supplier<V> vertexSupplier)
        Set the vertex supplier of the adapter.
        Parameters:
        vertexSupplier - the vertex supplier, or null to not support adding vertices via addVertex()
      • setEdgeSupplier

        public void setEdgeSupplier​(Supplier<E> edgeSupplier)
        Set the edge supplier of the adapter.
        Parameters:
        edgeSupplier - the edge supplier, or null to not support adding edges via addEdge(Object, Object)
      • getAllEdges

        public Set<E> getAllEdges​(V sourceVertex,
                                  V targetVertex)
      • getEdge

        public E getEdge​(V sourceVertex,
                         V targetVertex)
      • getVertexSupplier

        public Supplier<V> getVertexSupplier()
      • getEdgeSupplier

        public Supplier<E> getEdgeSupplier()
      • addEdge

        public E addEdge​(V sourceVertex,
                         V targetVertex)
      • addEdge

        public boolean addEdge​(V sourceVertex,
                               V targetVertex,
                               E e)
      • addVertex

        public V addVertex()
      • addVertex

        public boolean addVertex​(V v)
      • containsEdge

        public boolean containsEdge​(E e)
      • containsVertex

        public boolean containsVertex​(V v)
      • edgeSet

        public Set<E> edgeSet()
      • degreeOf

        public int degreeOf​(V vertex)
      • edgesOf

        public Set<E> edgesOf​(V vertex)
      • inDegreeOf

        public int inDegreeOf​(V vertex)
      • incomingEdgesOf

        public Set<E> incomingEdgesOf​(V vertex)
      • outDegreeOf

        public int outDegreeOf​(V vertex)
      • outgoingEdgesOf

        public Set<E> outgoingEdgesOf​(V vertex)
      • removeEdge

        public E removeEdge​(V sourceVertex,
                            V targetVertex)
      • removeEdge

        public boolean removeEdge​(E e)
      • removeVertex

        public boolean removeVertex​(V v)
      • vertexSet

        public Set<V> vertexSet()
      • getEdgeSource

        public V getEdgeSource​(E e)
      • getEdgeTarget

        public V getEdgeTarget​(E e)
      • getEdgeWeight

        public double getEdgeWeight​(E e)
      • setEdgeWeight

        public void setEdgeWeight​(E e,
                                  double weight)