## Class AbstractGraph<N>

• Type Parameters:
N - Node parameter type
All Implemented Interfaces:
Graph<N>
Direct Known Subclasses:
AbstractValueGraph, ImmutableGraph

@Beta
public abstract class AbstractGraph<N>
extends Object
implements Graph<N>
This class provides a skeletal implementation of Graph. It is recommended to extend this class rather than implement Graph directly.
Since:
20.0
Author:
James Sexton

• ### Method Detail

• #### edgeCount

protected long edgeCount()
Returns the number of edges in this graph; used to calculate the size of edges(). The default implementation is O(|N|). You can manually keep track of the number of edges and override this method for better performance.
• #### degree

public int degree(Object node)
Description copied from interface: Graph
Returns the count of node's incident edges, counting self-loops twice (equivalently, the number of times an edge touches node).

For directed graphs, this is equal to inDegree(node) + outDegree(node).

For undirected graphs, this is equal to adjacentNodes(node).size() + (1 if node has an incident self-loop, 0 otherwise).

If the count is greater than Integer.MAX_VALUE, returns Integer.MAX_VALUE.

Specified by:
degree in interface Graph<N>
• #### inDegree

public int inDegree(Object node)
Description copied from interface: Graph
Returns the count of node's incoming edges (equal to predecessors(node).size()) in a directed graph. In an undirected graph, returns the Graph.degree(Object).

If the count is greater than Integer.MAX_VALUE, returns Integer.MAX_VALUE.

Specified by:
inDegree in interface Graph<N>
• #### outDegree

public int outDegree(Object node)
Description copied from interface: Graph
Returns the count of node's outgoing edges (equal to successors(node).size()) in a directed graph. In an undirected graph, returns the Graph.degree(Object).

If the count is greater than Integer.MAX_VALUE, returns Integer.MAX_VALUE.

Specified by:
outDegree in interface Graph<N>
• #### toString

public String toString()
Returns a string representation of this graph.
Overrides:
toString in class Object