Class EndpointPair<N>
java.lang.Object
com.google.common.graph.EndpointPair<N>
- All Implemented Interfaces:
Iterable<N>
@Beta
@Immutable(containerOf="N")
public abstract class EndpointPair<N>
extends Object
implements Iterable<N>
An immutable pair representing the two endpoints of an edge in a graph. The
EndpointPair
of a directed edge is an ordered pair of nodes (source()
and target()
). The
EndpointPair
of an undirected edge is an unordered pair of nodes (nodeU()
and
nodeV()
).
The edge is a self-loop if, and only if, the two endpoints are equal.
- Since:
- 20.0
- Author:
- James Sexton
-
Method Summary
Modifier and TypeMethodDescriptionfinal N
adjacentNode
(N node) Returns the node that is adjacent tonode
along the origin edge.abstract boolean
abstract int
hashCode()
The hashcode of an orderedEndpointPair
is equal toObjects.hashCode(source(), target())
.abstract boolean
Returnstrue
if thisEndpointPair
is an ordered pair (i.e. represents the endpoints of a directed edge).final UnmodifiableIterator
<N> iterator()
final N
nodeU()
If thisEndpointPair
isOrdered()
returns thesource()
; otherwise, returns an arbitrary (but consistent) endpoint of the origin edge.final N
nodeV()
static <N> EndpointPair
<N> ordered
(N source, N target) Returns anEndpointPair
representing the endpoints of a directed edge.abstract N
source()
If thisEndpointPair
isOrdered()
, returns the node which is the source.abstract N
target()
If thisEndpointPair
isOrdered()
, returns the node which is the target.static <N> EndpointPair
<N> unordered
(N nodeU, N nodeV) Returns anEndpointPair
representing the endpoints of an undirected edge.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
ordered
Returns anEndpointPair
representing the endpoints of a directed edge. -
unordered
Returns anEndpointPair
representing the endpoints of an undirected edge. -
source
If thisEndpointPair
isOrdered()
, returns the node which is the source.- Throws:
UnsupportedOperationException
- if thisEndpointPair
is not ordered
-
target
If thisEndpointPair
isOrdered()
, returns the node which is the target.- Throws:
UnsupportedOperationException
- if thisEndpointPair
is not ordered
-
nodeU
If thisEndpointPair
isOrdered()
returns thesource()
; otherwise, returns an arbitrary (but consistent) endpoint of the origin edge. -
nodeV
Returns the nodeadjacent
tonodeU()
along the origin edge. If thisEndpointPair
isOrdered()
, this is equal totarget()
. -
adjacentNode
Returns the node that is adjacent tonode
along the origin edge.- Throws:
IllegalArgumentException
- if thisEndpointPair
does not containnode
- Since:
- 20.0 (but the argument type was changed from
Object
toN
in 31.0)
-
isOrdered
Returnstrue
if thisEndpointPair
is an ordered pair (i.e. represents the endpoints of a directed edge). -
iterator
-
equals
Two orderedEndpointPair
s are equal if theirsource()
andtarget()
are equal. Two unorderedEndpointPair
s are equal if they contain the same nodes. An orderedEndpointPair
is never equal to an unorderedEndpointPair
. -
hashCode
The hashcode of an orderedEndpointPair
is equal toObjects.hashCode(source(), target())
. The hashcode of an unorderedEndpointPair
is equal tonodeU().hashCode() + nodeV().hashCode()
.
-