Class MutableGraphAdapter<V>

  • Type Parameters:
    V - the graph vertex type
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, org.jgrapht.Graph<V,​com.google.common.graph.EndpointPair<V>>

    public class MutableGraphAdapter<V>
    extends BaseGraphAdapter<V,​com.google.common.graph.MutableGraph<V>>
    implements org.jgrapht.Graph<V,​com.google.common.graph.EndpointPair<V>>, java.lang.Cloneable, java.io.Serializable
    A graph adapter class using Guava's MutableGraph.

    The adapter uses class EndpointPair to represent edges. Changes in the adapter such as adding or removing vertices and edges are reflected in the underlying graph.

    See the example below on how to create such an adapter:

     MutableGraph<String> mutableGraph = GraphBuilder.directed().allowsSelfLoops(true).build();
     
     mutableGraph.addNode("v1");
     mutableGraph.addNode("v2");
     mutableGraph.addEdge("v1", "v2");
     
     Graph<String, EndpointPair<String>> graph = new MutableGraphAdapter<>(mutableGraph);
     
    Author:
    Dimitrios Michail
    See Also:
    Serialized Form
    • Constructor Detail

      • MutableGraphAdapter

        public MutableGraphAdapter​(com.google.common.graph.MutableGraph<V> graph)
        Create a new adapter.
        Parameters:
        graph - the graph
      • MutableGraphAdapter

        public MutableGraphAdapter​(com.google.common.graph.MutableGraph<V> 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

      • addEdge

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

        public boolean addEdge​(V sourceVertex,
                               V targetVertex,
                               com.google.common.graph.EndpointPair<V> e)
        The provided edge object can either be null or must respect the source and target vertices that are provided as parameters.
        Specified by:
        addEdge in interface org.jgrapht.Graph<V,​com.google.common.graph.EndpointPair<V>>
        Throws:
        java.lang.IllegalArgumentException - if edge e is not null and the sourceVertex parameter does not match the node U of the endpoint-pair
        java.lang.IllegalArgumentException - if edge e is not null and the targetVertex parameter does not match the node V of the endpoint-pair
      • addVertex

        public V addVertex()
        Specified by:
        addVertex in interface org.jgrapht.Graph<V,​com.google.common.graph.EndpointPair<V>>
      • addVertex

        public boolean addVertex​(V v)
        Specified by:
        addVertex in interface org.jgrapht.Graph<V,​com.google.common.graph.EndpointPair<V>>
      • removeEdge

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

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

        public boolean removeVertex​(V v)
        Specified by:
        removeVertex in interface org.jgrapht.Graph<V,​com.google.common.graph.EndpointPair<V>>
      • setEdgeWeight

        public void setEdgeWeight​(com.google.common.graph.EndpointPair<V> e,
                                  double weight)
        Specified by:
        setEdgeWeight in interface org.jgrapht.Graph<V,​com.google.common.graph.EndpointPair<V>>
      • clone

        public java.lang.Object clone()
        Returns a shallow copy of this graph instance. Neither edges nor vertices are cloned.
        Overrides:
        clone in class java.lang.Object
        Returns:
        a shallow copy of this graph.
        Throws:
        java.lang.RuntimeException - in case the clone is not supported
        See Also:
        Object.clone()