Class AbstractBaseGraph<N>
- java.lang.Object
-
- com.google.common.graph.AbstractBaseGraph<N>
-
- Type Parameters:
N- Node parameter type
- All Implemented Interfaces:
BaseGraph<N>,PredecessorsFunction<N>,SuccessorsFunction<N>
- Direct Known Subclasses:
AbstractGraph,AbstractValueGraph
abstract class AbstractBaseGraph<N> extends java.lang.Object implements BaseGraph<N>
This class provides a skeletal implementation ofBaseGraph.The methods implemented in this class should not be overridden unless the subclass admits a more efficient implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classAbstractBaseGraph.IncidentEdgeSet<N>
-
Constructor Summary
Constructors Constructor Description AbstractBaseGraph()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intdegree(N node)Returns the count ofnode's incident edges, counting self-loops twice (equivalently, the number of times an edge touchesnode).protected longedgeCount()Returns the number of edges in this graph; used to calculate the size ofedges().java.util.Set<EndpointPair<N>>edges()An implementation ofBaseGraph.edges()defined in terms ofBaseGraph.nodes()andBaseGraph.successors(Object).booleanhasEdgeConnecting(EndpointPair<N> endpoints)Returns true if there is an edge that directly connectsendpoints(in the order, if any, specified byendpoints).booleanhasEdgeConnecting(N nodeU, N nodeV)Returns true if there is an edge that directly connectsnodeUtonodeV.java.util.Set<EndpointPair<N>>incidentEdges(N node)Returns the edges in this graph whose endpoints includenode.intinDegree(N node)Returns the count ofnode's incoming edges (equal topredecessors(node).size()) in a directed graph.protected booleanisOrderingCompatible(EndpointPair<?> endpoints)intoutDegree(N node)Returns the count ofnode's outgoing edges (equal tosuccessors(node).size()) in a directed graph.protected voidvalidateEndpoints(EndpointPair<?> endpoints)ThrowsIllegalArgumentExceptionif the ordering ofendpointsis not compatible with the directionality of this graph.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.common.graph.BaseGraph
adjacentNodes, allowsSelfLoops, isDirected, nodeOrder, nodes, predecessors, successors
-
-
-
-
Method Detail
-
edgeCount
protected long edgeCount()
Returns the number of edges in this graph; used to calculate the size ofedges(). This implementation requires O(|N|) time. Classes extending this one may manually keep track of the number of edges as the graph is updated, and override this method for better performance.
-
edges
public java.util.Set<EndpointPair<N>> edges()
An implementation ofBaseGraph.edges()defined in terms ofBaseGraph.nodes()andBaseGraph.successors(Object).
-
incidentEdges
public java.util.Set<EndpointPair<N>> incidentEdges(N node)
Description copied from interface:BaseGraphReturns the edges in this graph whose endpoints includenode.This is equal to the union of incoming and outgoing edges.
- Specified by:
incidentEdgesin interfaceBaseGraph<N>
-
degree
public int degree(N node)
Description copied from interface:BaseGraphReturns the count ofnode's incident edges, counting self-loops twice (equivalently, the number of times an edge touchesnode).For directed graphs, this is equal to
inDegree(node) + outDegree(node).For undirected graphs, this is equal to
incidentEdges(node).size()+ (number of self-loops incident tonode).If the count is greater than
Integer.MAX_VALUE, returnsInteger.MAX_VALUE.
-
inDegree
public int inDegree(N node)
Description copied from interface:BaseGraphReturns the count ofnode's incoming edges (equal topredecessors(node).size()) in a directed graph. In an undirected graph, returns theBaseGraph.degree(Object).If the count is greater than
Integer.MAX_VALUE, returnsInteger.MAX_VALUE.
-
outDegree
public int outDegree(N node)
Description copied from interface:BaseGraphReturns the count ofnode's outgoing edges (equal tosuccessors(node).size()) in a directed graph. In an undirected graph, returns theBaseGraph.degree(Object).If the count is greater than
Integer.MAX_VALUE, returnsInteger.MAX_VALUE.
-
hasEdgeConnecting
public boolean hasEdgeConnecting(N nodeU, N nodeV)
Description copied from interface:BaseGraphReturns true if there is an edge that directly connectsnodeUtonodeV. This is equivalent tonodes().contains(nodeU) && successors(nodeU).contains(nodeV).In an undirected graph, this is equal to
hasEdgeConnecting(nodeV, nodeU).- Specified by:
hasEdgeConnectingin interfaceBaseGraph<N>
-
hasEdgeConnecting
public boolean hasEdgeConnecting(EndpointPair<N> endpoints)
Description copied from interface:BaseGraphReturns true if there is an edge that directly connectsendpoints(in the order, if any, specified byendpoints). This is equivalent toedges().contains(endpoints).Unlike the other
EndpointPair-accepting methods, this method does not throw if the endpoints are unordered; it simply returns false. This is for consistency with the behavior ofCollection#contains(Object)(which does not generally throw if the object cannot be present in the collection), and the desire to have this method's behavior be compatible withedges().contains(endpoints).- Specified by:
hasEdgeConnectingin interfaceBaseGraph<N>
-
validateEndpoints
protected final void validateEndpoints(EndpointPair<?> endpoints)
ThrowsIllegalArgumentExceptionif the ordering ofendpointsis not compatible with the directionality of this graph.
-
isOrderingCompatible
protected final boolean isOrderingCompatible(EndpointPair<?> endpoints)
-
-