Package org.jgrapht.graph.guava
Class MutableNetworkAdapter<V,E>
- java.lang.Object
-
- org.jgrapht.graph.AbstractGraph<V,E>
-
- org.jgrapht.graph.guava.BaseNetworkAdapter<V,E,com.google.common.graph.MutableNetwork<V,E>>
-
- org.jgrapht.graph.guava.MutableNetworkAdapter<V,E>
-
- Type Parameters:
V- the graph vertex typeE- 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'sMutableNetwork.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 Summary
Fields Modifier and Type Field Description protected static java.lang.StringGRAPH_IS_UNWEIGHTED-
Fields inherited from class org.jgrapht.graph.guava.BaseNetworkAdapter
edgeSupplier, LOOPS_NOT_ALLOWED, network, unmodifiableEdgeSet, unmodifiableVertexSet, vertexSupplier
-
-
Constructor Summary
Constructors Constructor Description MutableNetworkAdapter(com.google.common.graph.MutableNetwork<V,E> network)Create a new network adapter.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EaddEdge(V sourceVertex, V targetVertex)booleanaddEdge(V sourceVertex, V targetVertex, E e)VaddVertex()booleanaddVertex(V v)java.lang.Objectclone()Returns a shallow copy of this graph instance.booleanremoveEdge(E e)EremoveEdge(V sourceVertex, V targetVertex)booleanremoveVertex(V v)voidsetEdgeWeight(E e, double weight)-
Methods inherited from class org.jgrapht.graph.guava.BaseNetworkAdapter
containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeSource, getEdgeSupplier, getEdgeTarget, getEdgeWeight, getType, getVertexSupplier, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, setEdgeSupplier, setVertexSupplier, 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
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jgrapht.Graph
containsEdge, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeSource, getEdgeSupplier, getEdgeTarget, getEdgeWeight, getType, getVertexSupplier, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, removeAllEdges, removeAllEdges, removeAllVertices, setEdgeWeight, vertexSet
-
-
-
-
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 networkvertexSupplier- the vertex supplieredgeSupplier- the edge supplier
-
-
Method Detail
-
addVertex
public boolean addVertex(V v)
-
removeEdge
public boolean removeEdge(E e)
-
removeVertex
public boolean removeVertex(V v)
-
setEdgeWeight
public void setEdgeWeight(E e, double weight)
-
clone
public java.lang.Object clone()
Returns a shallow copy of this graph instance. Neither edges nor vertices are cloned.- Overrides:
clonein classjava.lang.Object- Returns:
- a shallow copy of this graph.
- Throws:
java.lang.RuntimeException- in case the clone is not supported- See Also:
Object.clone()
-
-