Class MutableNetworkAdapter<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 MutableNetworkAdapter<V,​E>
    extends BaseNetworkAdapter<V,​E,​com.google.common.graph.MutableNetwork<V,​E>>
    implements org.jgrapht.Graph<V,​E>, java.lang.Cloneable, java.io.Serializable
    A graph adapter class using Guava's MutableNetwork.

    Changes in the adapter such as adding or removing vertices and edges are reflected in the underlying network. Example usage:

     MutableNetwork<String, DefaultEdge> mutableNetwork =
         NetworkBuilder.directed().allowsParallelEdges(true).allowsSelfLoops(true).build();
     
     Graph<String, DefaultEdge> graph = new MutableNetworkAdapter<>(
         mutableNetwork, SupplierUtil.createStringSupplier(), SupplierUtil.DEFAULT_EDGE_SUPPLIER);
     
     graph.addVertex("v1");
     
     System.out.println(mutableNetwork.nodes().contains("v1")); // outputs true
     
    Author:
    Dimitrios Michail
    See Also:
    Serialized Form
    • Field Detail

      • GRAPH_IS_UNWEIGHTED

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

      • MutableNetworkAdapter

        public MutableNetworkAdapter​(com.google.common.graph.MutableNetwork<V,​E> network)
        Create a new network adapter.
        Parameters:
        network - the mutable network
      • MutableNetworkAdapter

        public MutableNetworkAdapter​(com.google.common.graph.MutableNetwork<V,​E> network,
                                     java.util.function.Supplier<V> vertexSupplier,
                                     java.util.function.Supplier<E> edgeSupplier)
        Create a new network adapter.
        Parameters:
        network - the mutable network
        vertexSupplier - the vertex supplier
        edgeSupplier - the edge supplier
    • 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>
      • setEdgeWeight

        public void setEdgeWeight​(E e,
                                  double weight)
        Specified by:
        setEdgeWeight in interface org.jgrapht.Graph<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()