Class ImmutableNetworkAdapter<V,​E>

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

    public class ImmutableNetworkAdapter<V,​E>
    extends BaseNetworkAdapter<V,​E,​com.google.common.graph.ImmutableNetwork<V,​E>>
    implements org.jgrapht.Graph<V,​E>, java.lang.Cloneable, java.io.Serializable
    A graph adapter class using Guava's ImmutableNetwork.

    Since the underlying network is immutable, the resulting graph is unmodifiable.

    Example usage:

     MutableNetwork<String, DefaultEdge> mutableNetwork =
         NetworkBuilder.directed().allowsParallelEdges(true).allowsSelfLoops(true).build();
     
     mutableNetwork.addNode("v1");
     
     ImmutableNetworkGraph<String, DefaultEdge> immutableNetwork =
         ImmutableNetwork.copyOf(mutableNetwork);
     
     Graph<String, DefaultEdge> graph = new ImmutableNetworkAdapter<>(immutableNetwork);
     
    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

      • ImmutableNetworkAdapter

        public ImmutableNetworkAdapter​(com.google.common.graph.ImmutableNetwork<V,​E> network)
        Create a new network adapter.
        Parameters:
        network - the immutable network
    • Method Detail

      • addEdge

        public E addEdge​(V sourceVertex,
                         V targetVertex)
        Specified by:
        addEdge in interface org.jgrapht.Graph<V,​E>
      • addEdge

        public boolean addEdge​(V sourceVertex,
                               V targetVertex,
                               E e)
        Specified by:
        addEdge in interface org.jgrapht.Graph<V,​E>
      • addVertex

        public V addVertex()
        Specified by:
        addVertex in interface org.jgrapht.Graph<V,​E>
      • addVertex

        public boolean addVertex​(V v)
        Specified by:
        addVertex in interface org.jgrapht.Graph<V,​E>
      • removeEdge

        public E removeEdge​(V sourceVertex,
                            V targetVertex)
        Specified by:
        removeEdge in interface org.jgrapht.Graph<V,​E>
      • removeEdge

        public boolean removeEdge​(E e)
        Specified by:
        removeEdge in interface org.jgrapht.Graph<V,​E>
      • removeVertex

        public boolean removeVertex​(V v)
        Specified by:
        removeVertex in interface org.jgrapht.Graph<V,​E>
      • getEdgeWeight

        public double getEdgeWeight​(E e)
        Specified by:
        getEdgeWeight in interface org.jgrapht.Graph<V,​E>
        Overrides:
        getEdgeWeight in class BaseNetworkAdapter<V,​E,​com.google.common.graph.ImmutableNetwork<V,​E>>
      • setEdgeWeight

        public void setEdgeWeight​(E e,
                                  double weight)
        Specified by:
        setEdgeWeight in interface org.jgrapht.Graph<V,​E>
      • getType

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