Class GuavaValueGraphAdapter<V,E,ValueT>
- java.lang.Object
-
- com.google.common.graph.AbstractValueGraph<V,ValueT>
-
- com.jgalgo.adapt.guava.GuavaValueGraphAdapter<V,E,ValueT>
-
- Type Parameters:
V
- the vertices typeE
- the edges typeValueT
- the values type
- All Implemented Interfaces:
PredecessorsFunction<V>
,SuccessorsFunction<V>
,ValueGraph<V,ValueT>
- Direct Known Subclasses:
GuavaMutableValueGraphAdapter
public class GuavaValueGraphAdapter<V,E,ValueT> extends AbstractValueGraph<V,ValueT>
An adapter from a JGAlgo graph to a Guava value graph.The adapter is constructed with a JGAlgo graph and implements the Guava value graph interface, and can be used with any Guava algorithm. The adapter is a live view, so any change in the JGAlgo graph is reflected in the Guava graph and vice versa, but the underlying JGAlgo graph should not be modified directly.
The Guava value graph is immutable, so as this adapter. A subclass of this adapter,
GuavaMutableValueGraphAdapter
, is a mutable adapter that implements the Guava mutable value graph interface.Parallel edges are not supported by Guava value graph, therefore the adapter will throw an UnsupportedOperationException if the underlying JGAlgo graph allows parallel edges. Whether this graph is directed or not, and whether it support self edges or not, is determined by the underlying JGAlgo graph.
The Guava value graph represent connections between nodes with value for each connection. Each connection has a non unique value, similar to a map from the endpoints to the value. The values of the edges are represented as weights in the underlying JGAlgo graph, and weights the key is passed in the constructor, see Graph.edgesWeights(String). The type of the value is specified as a generic
ValueT
parameter. The edge generic typeE
is not reflected in the Guava graph, and is only used internally for safe access to the underlying JGAlgo graph.Guava support different element orders for the nodes and the incident edges. This adapter uses the default element order, which is unordered, and cannot be changed as the underlying JGAlgo graph does not support any other order.
Among Guava
Graph
,ValueGraph
andNetwork
, the network is the most similar to JGAlgo graphs, as vertices and edges have unique identifiers, and queries of edges are answered with the edges identifiers. On the other had, the Graph and ValueGraph do not support unique identifiers for the edges, and operations on edges are addressed by a pair of nodes. The ValueGraph does associate a value with each edge, be it does not have to be unique, and it is more similar to weights in JGAlgo graphs.For adapting the other way around, from Guava to JGAlgo, only from Guava Network is supported, see
GuavaNetworkWrapper
.- Author:
- Barak Ugav
- See Also:
Graph
,ValueGraph
,GuavaMutableValueGraphAdapter
-
-
Constructor Summary
Constructors Constructor Description GuavaValueGraphAdapter(Graph<V,E> graph, String edgeWeightKey)
Constructs a new adapter from the given JGAlgo graph.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<V>
adjacentNodes(V node)
boolean
allowsSelfLoops()
Graph<V>
asGraph()
int
degree(V node)
Set<EndpointPair<V>>
edges()
ValueT
edgeValueOrDefault(EndpointPair<V> endpoints, ValueT defaultValue)
ValueT
edgeValueOrDefault(V nodeU, V nodeV, ValueT defaultValue)
boolean
hasEdgeConnecting(EndpointPair<V> endpoints)
boolean
hasEdgeConnecting(V nodeU, V nodeV)
ElementOrder<V>
incidentEdgeOrder()
Set<EndpointPair<V>>
incidentEdges(V node)
int
inDegree(V node)
boolean
isDirected()
ElementOrder<V>
nodeOrder()
Set<V>
nodes()
int
outDegree(V node)
Set<V>
predecessors(V node)
Set<V>
successors(V node)
-
-
-
Constructor Detail
-
GuavaValueGraphAdapter
public GuavaValueGraphAdapter(Graph<V,E> graph, String edgeWeightKey)
Constructs a new adapter from the given JGAlgo graph.- Parameters:
graph
- the JGAlgo graphedgeWeightKey
- the key of the weights of the edges, which are the values of the value graph- Throws:
IllegalArgumentException
- if the graph does not contain edge weights for the given keyUnsupportedOperationException
- if the graph allows parallel edges
-
-
Method Detail
-
edges
public Set<EndpointPair<V>> edges()
- Specified by:
edges
in interfaceValueGraph<V,E>
-
incidentEdges
public Set<EndpointPair<V>> incidentEdges(V node)
- Specified by:
incidentEdges
in interfaceValueGraph<V,E>
-
hasEdgeConnecting
public boolean hasEdgeConnecting(V nodeU, V nodeV)
- Specified by:
hasEdgeConnecting
in interfaceValueGraph<V,E>
-
hasEdgeConnecting
public boolean hasEdgeConnecting(EndpointPair<V> endpoints)
- Specified by:
hasEdgeConnecting
in interfaceValueGraph<V,E>
-
degree
public int degree(V node)
- Specified by:
degree
in interfaceValueGraph<V,E>
-
outDegree
public int outDegree(V node)
- Specified by:
outDegree
in interfaceValueGraph<V,E>
-
inDegree
public int inDegree(V node)
- Specified by:
inDegree
in interfaceValueGraph<V,E>
-
asGraph
public Graph<V> asGraph()
- Specified by:
asGraph
in interfaceValueGraph<V,E>
- Overrides:
asGraph
in classAbstractValueGraph<V,ValueT>
-
isDirected
public boolean isDirected()
-
allowsSelfLoops
public boolean allowsSelfLoops()
-
nodeOrder
public ElementOrder<V> nodeOrder()
-
incidentEdgeOrder
public ElementOrder<V> incidentEdgeOrder()
- Specified by:
incidentEdgeOrder
in interfaceValueGraph<V,E>
-
edgeValueOrDefault
public ValueT edgeValueOrDefault(EndpointPair<V> endpoints, ValueT defaultValue)
-
-