Class BaseGraphAdapter<V,​G extends com.google.common.graph.Graph<V>>

  • Type Parameters:
    V - the graph vertex type
    G - type of the underlying Guava's graph
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, org.jgrapht.Graph<V,​com.google.common.graph.EndpointPair<V>>
    Direct Known Subclasses:
    ImmutableGraphAdapter, MutableGraphAdapter

    public abstract class BaseGraphAdapter<V,​G extends com.google.common.graph.Graph<V>>
    extends org.jgrapht.graph.AbstractGraph<V,​com.google.common.graph.EndpointPair<V>>
    implements org.jgrapht.Graph<V,​com.google.common.graph.EndpointPair<V>>, java.lang.Cloneable, java.io.Serializable
    A base abstract implementation for the graph adapter class using Guava's Graph. This is a helper class in order to support both mutable and immutable graphs.
    Author:
    Dimitrios Michail
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.function.Supplier<com.google.common.graph.EndpointPair<V>> edgeSupplier  
      protected G graph  
      protected static java.lang.String LOOPS_NOT_ALLOWED  
      protected java.util.Set<com.google.common.graph.EndpointPair<V>> unmodifiableEdgeSet  
      protected java.util.Set<V> unmodifiableVertexSet  
      protected java.util.function.Supplier<V> vertexSupplier  
      • Fields inherited from interface org.jgrapht.Graph

        DEFAULT_EDGE_WEIGHT
    • Constructor Summary

      Constructors 
      Constructor Description
      BaseGraphAdapter​(G graph)
      Create a new adapter.
      BaseGraphAdapter​(G graph, java.util.function.Supplier<V> vertexSupplier, java.util.function.Supplier<com.google.common.graph.EndpointPair<V>> edgeSupplier)
      Create a new adapter.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean containsEdge​(com.google.common.graph.EndpointPair<V> e)  
      boolean containsVertex​(V v)  
      int degreeOf​(V vertex)  
      java.util.Set<com.google.common.graph.EndpointPair<V>> edgeSet()  
      java.util.Set<com.google.common.graph.EndpointPair<V>> edgesOf​(V vertex)  
      java.util.Set<com.google.common.graph.EndpointPair<V>> getAllEdges​(V sourceVertex, V targetVertex)  
      com.google.common.graph.EndpointPair<V> getEdge​(V sourceVertex, V targetVertex)  
      V getEdgeSource​(com.google.common.graph.EndpointPair<V> e)  
      java.util.function.Supplier<com.google.common.graph.EndpointPair<V>> getEdgeSupplier()  
      V getEdgeTarget​(com.google.common.graph.EndpointPair<V> e)  
      double getEdgeWeight​(com.google.common.graph.EndpointPair<V> e)  
      org.jgrapht.GraphType getType()  
      java.util.function.Supplier<V> getVertexSupplier()  
      java.util.Set<com.google.common.graph.EndpointPair<V>> incomingEdgesOf​(V vertex)  
      int inDegreeOf​(V vertex)  
      int outDegreeOf​(V vertex)  
      java.util.Set<com.google.common.graph.EndpointPair<V>> outgoingEdgesOf​(V vertex)  
      void setEdgeSupplier​(java.util.function.Supplier<com.google.common.graph.EndpointPair<V>> edgeSupplier)
      Set the edge supplier that the graph uses whenever it needs to create new edges.
      void setVertexSupplier​(java.util.function.Supplier<V> vertexSupplier)
      Set the vertex supplier that the graph uses whenever it needs to create new vertices.
      java.util.Set<V> vertexSet()  
      • Methods inherited from class org.jgrapht.graph.AbstractGraph

        assertVertexExist, containsEdge, equals, hashCode, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.jgrapht.Graph

        addEdge, addEdge, addVertex, addVertex, containsEdge, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, setEdgeWeight, setEdgeWeight
    • Field Detail

      • LOOPS_NOT_ALLOWED

        protected static final java.lang.String LOOPS_NOT_ALLOWED
        See Also:
        Constant Field Values
      • unmodifiableVertexSet

        protected transient java.util.Set<V> unmodifiableVertexSet
      • unmodifiableEdgeSet

        protected transient java.util.Set<com.google.common.graph.EndpointPair<V>> unmodifiableEdgeSet
      • vertexSupplier

        protected java.util.function.Supplier<V> vertexSupplier
      • edgeSupplier

        protected java.util.function.Supplier<com.google.common.graph.EndpointPair<V>> edgeSupplier
      • graph

        protected transient G extends com.google.common.graph.Graph<V> graph
    • Constructor Detail

      • BaseGraphAdapter

        public BaseGraphAdapter​(G graph)
        Create a new adapter.
        Parameters:
        graph - the graph
      • BaseGraphAdapter

        public BaseGraphAdapter​(G graph,
                                java.util.function.Supplier<V> vertexSupplier,
                                java.util.function.Supplier<com.google.common.graph.EndpointPair<V>> edgeSupplier)
        Create a new adapter.
        Parameters:
        graph - the graph
        vertexSupplier - the vertex supplier
        edgeSupplier - the edge supplier
    • Method Detail

      • getVertexSupplier

        public java.util.function.Supplier<V> getVertexSupplier()
        Specified by:
        getVertexSupplier in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • setVertexSupplier

        public void setVertexSupplier​(java.util.function.Supplier<V> vertexSupplier)
        Set the vertex supplier that the graph uses whenever it needs to create new vertices.

        A graph uses the vertex supplier to create new vertex objects whenever a user calls method Graph.addVertex(). Users can also create the vertex in user code and then use method Graph.addVertex(Object) to add the vertex.

        In contrast with the Supplier interface, the vertex supplier has the additional requirement that a new and distinct result is returned every time it is invoked. More specifically for a new vertex to be added in a graph v must not be equal to any other vertex in the graph. More formally, the graph must not contain any vertex v2 such that v2.equals(v).

        Parameters:
        vertexSupplier - the vertex supplier
      • getEdgeSupplier

        public java.util.function.Supplier<com.google.common.graph.EndpointPair<V>> getEdgeSupplier()
        Specified by:
        getEdgeSupplier in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • setEdgeSupplier

        public void setEdgeSupplier​(java.util.function.Supplier<com.google.common.graph.EndpointPair<V>> edgeSupplier)
        Set the edge supplier that the graph uses whenever it needs to create new edges.

        A graph uses the edge supplier to create new edge objects whenever a user calls method Graph.addEdge(Object, Object). Users can also create the edge in user code and then use method Graph.addEdge(Object, Object, Object) to add the edge.

        In contrast with the Supplier interface, the edge supplier has the additional requirement that a new and distinct result is returned every time it is invoked. More specifically for a new edge to be added in a graph e must not be equal to any other edge in the graph (even if the graph allows edge-multiplicity). More formally, the graph must not contain any edge e2 such that e2.equals(e).

        Parameters:
        edgeSupplier - the edge supplier
      • getEdge

        public com.google.common.graph.EndpointPair<V> getEdge​(V sourceVertex,
                                                               V targetVertex)
        Specified by:
        getEdge in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • vertexSet

        public java.util.Set<V> vertexSet()
        Specified by:
        vertexSet in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • getEdgeSource

        public V getEdgeSource​(com.google.common.graph.EndpointPair<V> e)
        Specified by:
        getEdgeSource in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • getEdgeTarget

        public V getEdgeTarget​(com.google.common.graph.EndpointPair<V> e)
        Specified by:
        getEdgeTarget in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • getType

        public org.jgrapht.GraphType getType()
        Specified by:
        getType in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • containsEdge

        public boolean containsEdge​(com.google.common.graph.EndpointPair<V> e)
        Specified by:
        containsEdge in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • containsVertex

        public boolean containsVertex​(V v)
        Specified by:
        containsVertex in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • edgeSet

        public java.util.Set<com.google.common.graph.EndpointPair<V>> edgeSet()
        Specified by:
        edgeSet in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • degreeOf

        public int degreeOf​(V vertex)
        Specified by:
        degreeOf in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • edgesOf

        public java.util.Set<com.google.common.graph.EndpointPair<V>> edgesOf​(V vertex)
        Specified by:
        edgesOf in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • inDegreeOf

        public int inDegreeOf​(V vertex)
        Specified by:
        inDegreeOf in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • incomingEdgesOf

        public java.util.Set<com.google.common.graph.EndpointPair<V>> incomingEdgesOf​(V vertex)
        Specified by:
        incomingEdgesOf in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • outDegreeOf

        public int outDegreeOf​(V vertex)
        Specified by:
        outDegreeOf in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • outgoingEdgesOf

        public java.util.Set<com.google.common.graph.EndpointPair<V>> outgoingEdgesOf​(V vertex)
        Specified by:
        outgoingEdgesOf in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • getEdgeWeight

        public double getEdgeWeight​(com.google.common.graph.EndpointPair<V> e)
        Specified by:
        getEdgeWeight in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>
      • getAllEdges

        public java.util.Set<com.google.common.graph.EndpointPair<V>> getAllEdges​(V sourceVertex,
                                                                                  V targetVertex)
        Specified by:
        getAllEdges in interface org.jgrapht.Graph<V,​G extends com.google.common.graph.Graph<V>>