Package com.google.common.graph
Class EndpointPair<N>
- java.lang.Object
-
- com.google.common.graph.EndpointPair<N>
-
- All Implemented Interfaces:
java.lang.Iterable<N>
- Direct Known Subclasses:
EndpointPair.Ordered,EndpointPair.Unordered
public abstract class EndpointPair<N> extends java.lang.Object implements java.lang.Iterable<N>An immutable pair representing the two endpoints of an edge in a graph. TheEndpointPairof a directed edge is an ordered pair of nodes (source()andtarget()). TheEndpointPairof an undirected edge is an unordered pair of nodes (nodeU()andnodeV()).The edge is a self-loop if, and only if, the two endpoints are equal.
- Since:
- 20.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classEndpointPair.Ordered<N>private static classEndpointPair.Unordered<N>
-
Constructor Summary
Constructors Modifier Constructor Description privateEndpointPair(N nodeU, N nodeV)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description NadjacentNode(java.lang.Object node)Returns the node that is adjacent tonodealong the origin edge.abstract booleanequals(java.lang.Object obj)abstract inthashCode()The hashcode of an orderedEndpointPairis equal toObjects.hashCode(source(), target()).abstract booleanisOrdered()Returnstrueif thisEndpointPairis an ordered pair (i.e.UnmodifiableIterator<N>iterator()NnodeU()If thisEndpointPairisOrdered()returns thesource(); otherwise, returns an arbitrary (but consistent) endpoint of the origin edge.NnodeV()(package private) static <N> EndpointPair<N>of(Graph<?> graph, N nodeU, N nodeV)Returns anEndpointPairrepresenting the endpoints of an edge ingraph.(package private) static <N> EndpointPair<N>of(Network<?,?> network, N nodeU, N nodeV)Returns anEndpointPairrepresenting the endpoints of an edge innetwork.static <N> EndpointPair<N>ordered(N source, N target)Returns anEndpointPairrepresenting the endpoints of a directed edge.abstract Nsource()If thisEndpointPairisOrdered(), returns the node which is the source.abstract Ntarget()If thisEndpointPairisOrdered(), returns the node which is the target.static <N> EndpointPair<N>unordered(N nodeU, N nodeV)Returns anEndpointPairrepresenting the endpoints of an undirected edge.
-
-
-
Method Detail
-
ordered
public static <N> EndpointPair<N> ordered(N source, N target)
Returns anEndpointPairrepresenting the endpoints of a directed edge.
-
unordered
public static <N> EndpointPair<N> unordered(N nodeU, N nodeV)
Returns anEndpointPairrepresenting the endpoints of an undirected edge.
-
of
static <N> EndpointPair<N> of(Graph<?> graph, N nodeU, N nodeV)
Returns anEndpointPairrepresenting the endpoints of an edge ingraph.
-
of
static <N> EndpointPair<N> of(Network<?,?> network, N nodeU, N nodeV)
Returns anEndpointPairrepresenting the endpoints of an edge innetwork.
-
source
public abstract N source()
If thisEndpointPairisOrdered(), returns the node which is the source.- Throws:
java.lang.UnsupportedOperationException- if thisEndpointPairis not ordered
-
target
public abstract N target()
If thisEndpointPairisOrdered(), returns the node which is the target.- Throws:
java.lang.UnsupportedOperationException- if thisEndpointPairis not ordered
-
nodeU
public final N nodeU()
If thisEndpointPairisOrdered()returns thesource(); otherwise, returns an arbitrary (but consistent) endpoint of the origin edge.
-
nodeV
public final N nodeV()
Returns the nodeadjacenttonodeU()along the origin edge. If thisEndpointPairisOrdered(), this is equal totarget().
-
adjacentNode
public final N adjacentNode(java.lang.Object node)
Returns the node that is adjacent tonodealong the origin edge.- Throws:
java.lang.IllegalArgumentException- if thisEndpointPairdoes not containnode
-
isOrdered
public abstract boolean isOrdered()
Returnstrueif thisEndpointPairis an ordered pair (i.e. represents the endpoints of a directed edge).
-
iterator
public final UnmodifiableIterator<N> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<N>
-
equals
public abstract boolean equals(java.lang.Object obj)
Two orderedEndpointPairs are equal if theirsource()andtarget()are equal. Two unorderedEndpointPairs are equal if they contain the same nodes. An orderedEndpointPairis never equal to an unorderedEndpointPair.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public abstract int hashCode()
The hashcode of an orderedEndpointPairis equal toObjects.hashCode(source(), target()). The hashcode of an unorderedEndpointPairis equal tonodeU().hashCode() + nodeV().hashCode().- Overrides:
hashCodein classjava.lang.Object
-
-