Package org.jgrapht.graph.guava
Class MutableGraphAdapter<V>
- java.lang.Object
-
- org.jgrapht.graph.AbstractGraph<V,com.google.common.graph.EndpointPair<V>>
-
- org.jgrapht.graph.guava.BaseGraphAdapter<V,com.google.common.graph.MutableGraph<V>>
-
- org.jgrapht.graph.guava.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'sMutableGraph.The adapter uses class
EndpointPairto 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
-
-
Field Summary
-
Fields inherited from class org.jgrapht.graph.guava.BaseGraphAdapter
edgeSupplier, graph, LOOPS_NOT_ALLOWED, unmodifiableEdgeSet, unmodifiableVertexSet, vertexSupplier
-
-
Constructor Summary
Constructors Constructor Description MutableGraphAdapter(com.google.common.graph.MutableGraph<V> graph)Create a new adapter.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.google.common.graph.EndpointPair<V>addEdge(V sourceVertex, V targetVertex)booleanaddEdge(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.VaddVertex()booleanaddVertex(V v)java.lang.Objectclone()Returns a shallow copy of this graph instance.booleanremoveEdge(com.google.common.graph.EndpointPair<V> e)com.google.common.graph.EndpointPair<V>removeEdge(V sourceVertex, V targetVertex)booleanremoveVertex(V v)voidsetEdgeWeight(com.google.common.graph.EndpointPair<V> e, double weight)-
Methods inherited from class org.jgrapht.graph.guava.BaseGraphAdapter
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
-
-
-
-
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 graphvertexSupplier- the vertex supplieredgeSupplier- the edge supplier
-
-
Method Detail
-
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:
addEdgein interfaceorg.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-pairjava.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()
-
addVertex
public boolean addVertex(V v)
-
removeEdge
public com.google.common.graph.EndpointPair<V> removeEdge(V sourceVertex, V targetVertex)
-
removeEdge
public boolean removeEdge(com.google.common.graph.EndpointPair<V> e)
-
removeVertex
public boolean removeVertex(V v)
-
setEdgeWeight
public void setEdgeWeight(com.google.common.graph.EndpointPair<V> 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()
-
-