Class ImmutableGraphAdapter<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 ImmutableGraphAdapter<V>
    extends BaseGraphAdapter<V,​com.google.common.graph.ImmutableGraph<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 ImmutableGraph.

    The adapter uses class EndpointPair to represent edges. Since the underlying graph is immutable, the resulting graph is unmodifiable.

    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");
     
     ImmutableGraph<String> immutableGraph = ImmutableGraph.copyOf(mutableGraph);
     
     Graph<String, EndpointPair<String>> graph = new ImmutableGraphAdapter<>(immutableGraph);
     
    Author:
    Dimitrios Michail
    See Also:
    Serialized Form
    • Field Detail

      • GRAPH_IS_IMMUTABLE

        protected static final java.lang.String GRAPH_IS_IMMUTABLE
        See Also:
        Constant Field Values
    • Constructor Detail

      • ImmutableGraphAdapter

        public ImmutableGraphAdapter​(com.google.common.graph.ImmutableGraph<V> graph)
        Create a new adapter.
        Parameters:
        graph - the graph
    • 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)
        Specified by:
        addEdge in interface org.jgrapht.Graph<V,​com.google.common.graph.EndpointPair<V>>
      • 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>>
      • getType

        public org.jgrapht.GraphType getType()
        Specified by:
        getType in interface org.jgrapht.Graph<V,​com.google.common.graph.EndpointPair<V>>
        Overrides:
        getType in class BaseGraphAdapter<V,​com.google.common.graph.ImmutableGraph<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()