V - the graph vertex typeE - the graph edge typepublic class ImmutableNetworkAdapter<V,E> extends BaseNetworkAdapter<V,E,com.google.common.graph.ImmutableNetwork<V,E>> implements Graph<V,E>, Cloneable, Serializable
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);
| Modifier and Type | Field and Description |
|---|---|
protected static String |
GRAPH_IS_IMMUTABLE |
edgeSupplier, LOOPS_NOT_ALLOWED, network, unmodifiableEdgeSet, unmodifiableVertexSet, vertexSupplierDEFAULT_EDGE_WEIGHT| Constructor and Description |
|---|
ImmutableNetworkAdapter(com.google.common.graph.ImmutableNetwork<V,E> network)
Create a new network adapter.
|
| Modifier and Type | Method and Description |
|---|---|
E |
addEdge(V sourceVertex,
V targetVertex)
Creates a new edge in this graph, going from the source vertex to the target vertex, and
returns the created edge.
|
boolean |
addEdge(V sourceVertex,
V targetVertex,
E e)
Adds the specified edge to this graph, going from the source vertex to the target vertex.
|
V |
addVertex()
Creates a new vertex in this graph and returns it.
|
boolean |
addVertex(V v)
Adds the specified vertex to this graph if not already present.
|
Object |
clone()
Returns a shallow copy of this graph instance.
|
double |
getEdgeWeight(E e)
Returns the weight assigned to a given edge.
|
GraphType |
getType()
Get the graph type.
|
boolean |
removeEdge(E e)
Removes the specified edge from the graph.
|
E |
removeEdge(V sourceVertex,
V targetVertex)
Removes an edge going from source vertex to target vertex, if such vertices and such edge
exist in this graph.
|
boolean |
removeVertex(V v)
Removes the specified vertex from this graph including all its touching edges if present.
|
void |
setEdgeWeight(E e,
double weight)
Assigns a weight to an edge.
|
containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeSupplier, getEdgeTarget, getVertexSupplier, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, setEdgeSupplier, setVertexSupplier, vertexSetassertVertexExist, containsEdge, equals, hashCode, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSetsfinalize, getClass, notify, notifyAll, wait, wait, waitcontainsEdge, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeSupplier, getEdgeTarget, getVertexSupplier, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, removeAllEdges, removeAllEdges, removeAllVertices, vertexSetprotected static final String GRAPH_IS_IMMUTABLE
public E addEdge(V sourceVertex, V targetVertex)
Graphnull.
The source and target vertices must already be contained in this graph. If they are not found
in graph IllegalArgumentException is thrown.
This method creates the new edge e using this graph's edge supplier (see
Graph.getEdgeSupplier()). For the new edge to be added e must not be
equal to any other edge the graph (even if the graph allows edge-multiplicity). More
formally, the graph must not contain any edge e2 such that
e2.equals(e). If such
e2 is found then the newly created edge e is abandoned, the method leaves
this graph unchanged and returns null.
If the underlying graph implementation's Graph.getEdgeSupplier() returns
null, then this method cannot create edges and throws an
UnsupportedOperationException.
addEdge in interface Graph<V,E>sourceVertex - source vertex of the edge.targetVertex - target vertex of the edge.
null.Graph.getEdgeSupplier()public boolean addEdge(V sourceVertex, V targetVertex, E e)
Graph
e, to this graph if this graph contains no edge e2 such that
e2.equals(e). If this graph already contains such an edge, the call leaves this
graph unchanged and returns false. Some graphs do not allow edge-multiplicity. In
such cases, if the graph already contains an edge from the specified source to the specified
target, than this method does not change the graph and returns
false. If the edge was added to the graph, returns
true.
The source and target vertices must already be contained in this graph. If they are not found in graph IllegalArgumentException is thrown.
addEdge in interface Graph<V,E>sourceVertex - source vertex of the edge.targetVertex - target vertex of the edge.e - edge to be added to this graph.Graph.addEdge(Object, Object),
Graph.getEdgeSupplier()public V addVertex()
Graph
This method creates the new vertex v using this graph's vertex supplier (see
Graph.getVertexSupplier()). For the new vertex to be added v must not
be equal to any other vertex in the graph. More formally, the graph must not contain any
vertex v2 such that v2.equals(v). If such
v2 is found then the newly created vertex v is abandoned, the method
leaves this graph unchanged and returns null.
If the underlying graph implementation's Graph.getVertexSupplier() returns
null, then this method cannot create vertices and throws an
UnsupportedOperationException.
addVertex in interface Graph<V,E>null.Graph.getVertexSupplier()public boolean addVertex(V v)
Graphv, to this graph if this graph contains no vertex
u such that
u.equals(v). If this graph already contains such vertex, the call leaves this graph
unchanged and returns false. In combination with the restriction on constructors,
this ensures that graphs never contain duplicate vertices.public E removeEdge(V sourceVertex, V targetVertex)
Graphnull otherwise.removeEdge in interface Graph<V,E>sourceVertex - source vertex of the edge.targetVertex - target vertex of the edge.null if no edge removed.public boolean removeEdge(E e)
Graph
e2 such that e2.equals(e), if the graph contains such edge. Returns
true if the graph contained the specified edge. (The graph will not contain the
specified edge once the call returns).
If the specified edge is null returns
false.
removeEdge in interface Graph<V,E>e - edge to be removed from this graph, if present.true if and only if the graph contained the specified edge.public boolean removeVertex(V v)
Graph
u such that u.equals(v), the call removes all edges that touch
u and then removes u itself. If no such u is found,
the call leaves the graph unchanged. Returns true if the graph contained the
specified vertex. (The graph will not contain the specified vertex once the call returns).
If the specified vertex is null returns
false.
removeVertex in interface Graph<V,E>v - vertex to be removed from this graph, if present.true if the graph contained the specified vertex; false
otherwise.public double getEdgeWeight(E e)
GraphGraph.DEFAULT_EDGE_WEIGHT), allowing weighted-graph algorithms to apply to them when
meaningful.getEdgeWeight in interface Graph<V,E>getEdgeWeight in class BaseNetworkAdapter<V,E,com.google.common.graph.ImmutableNetwork<V,E>>e - edge of interestpublic void setEdgeWeight(E e, double weight)
GraphsetEdgeWeight in interface Graph<V,E>e - edge on which to set weightweight - new weight for edgepublic GraphType getType()
Graphpublic Object clone()
clone in class ObjectRuntimeException - in case the clone is not supportedObject.clone()Copyright © 2018. All rights reserved.