Class GuavaGraphAdapter<V,E>
- java.lang.Object
-
- com.google.common.graph.AbstractGraph<V>
-
- com.jgalgo.adapt.guava.GuavaGraphAdapter<V,E>
-
- Type Parameters:
V
- the vertices typeE
- the edges type
- All Implemented Interfaces:
Graph<V>
,PredecessorsFunction<V>
,SuccessorsFunction<V>
- Direct Known Subclasses:
GuavaMutableGraphAdapter
public class GuavaGraphAdapter<V,E> extends AbstractGraph<V>
An adapter from a JGAlgo graph to a Guava graph.The adapter is constructed with a JGAlgo graph and implements the Guava 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 basic Guava graph is immutable, so as this adapter. A subclass of this adapter,
GuavaMutableGraphAdapter
, is a mutable adapter that implements the Guava mutable graph interface.Parallel edges are not supported by Guava basic 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.
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.
The basic Guava graph only represent connections between nodes, without addressing the edges themselves. The edge generic type
E
is not reflected in the Guava graph, and is only internally for safe access to the underlying JGAlgo graph.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
,Graph
,GuavaMutableGraphAdapter
-
-
Constructor Summary
Constructors Constructor Description GuavaGraphAdapter(Graph<V,E> graph)
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()
int
degree(V node)
protected long
edgeCount()
Set<EndpointPair<V>>
edges()
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()
protected boolean
isOrderingCompatible(EndpointPair<?> arg0)
ElementOrder<V>
nodeOrder()
Set<V>
nodes()
int
outDegree(V node)
Set<V>
predecessors(V node)
Set<V>
successors(V node)
protected void
validateEndpoints(EndpointPair<?> arg0)
-
Methods inherited from class com.google.common.graph.AbstractGraph
equals, hashCode, toString
-
-
-
-
Constructor Detail
-
GuavaGraphAdapter
public GuavaGraphAdapter(Graph<V,E> graph)
Constructs a new adapter from the given JGAlgo graph.- Parameters:
graph
- the JGAlgo graph- Throws:
UnsupportedOperationException
- if the graph allows parallel edges
-
-
Method Detail
-
hasEdgeConnecting
public boolean hasEdgeConnecting(EndpointPair<V> endpoints)
- Specified by:
hasEdgeConnecting
in interfaceGraph<V>
-
hasEdgeConnecting
public boolean hasEdgeConnecting(V nodeU, V nodeV)
- Specified by:
hasEdgeConnecting
in interfaceGraph<V>
-
incidentEdges
public Set<EndpointPair<V>> incidentEdges(V node)
- Specified by:
incidentEdges
in interfaceGraph<V>
-
isDirected
public boolean isDirected()
-
allowsSelfLoops
public boolean allowsSelfLoops()
-
incidentEdgeOrder
public ElementOrder<V> incidentEdgeOrder()
- Specified by:
incidentEdgeOrder
in interfaceGraph<V>
-
nodeOrder
public ElementOrder<V> nodeOrder()
-
edgeCount
protected long edgeCount()
-
validateEndpoints
protected final void validateEndpoints(EndpointPair<?> arg0)
-
isOrderingCompatible
protected final boolean isOrderingCompatible(EndpointPair<?> arg0)
-
-