Package com.google.common.graph
Class EndpointPair<N>
-
- com.google.common.graph.EndpointPair<N>
-
- All Implemented Interfaces:
<N>
@Beta (="N") public abstract class EndpointPair<N> extends implements <N>
An immutable pair representing the two endpoints of an edge in a graph. TheEndpointPair
of a directed edge is an ordered pair of nodes (source()
andtarget()
). TheEndpointPair
of 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
- Author:
- James Sexton
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description N
node)
Returns the node that is adjacent tonode
along the origin edge.abstract boolean
obj)
abstract int
hashCode()
The hashcode of an orderedEndpointPair
is equal toObjects.hashCode(source(), target())
.abstract boolean
isOrdered()
Returnstrue
if thisEndpointPair
is an ordered pair (i.e.UnmodifiableIterator<N>
iterator()
N
nodeU()
If thisEndpointPair
isOrdered()
returns thesource()
; otherwise, returns an arbitrary (but consistent) endpoint of the origin edge.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.
-
-
-
Method Detail
-
ordered
public static <N> EndpointPair<N> ordered(N source, N target)
Returns anEndpointPair
representing the endpoints of a directed edge.
-
unordered
public static <N> EndpointPair<N> unordered(N nodeU, N nodeV)
Returns anEndpointPair
representing the endpoints of an undirected edge.
-
source
public abstract N source()
If thisEndpointPair
isOrdered()
, returns the node which is the source.- Throws:
- if this
EndpointPair
is not ordered
-
target
public abstract N target()
If thisEndpointPair
isOrdered()
, returns the node which is the target.- Throws:
- if this
EndpointPair
is not ordered
-
nodeU
public final N nodeU()
If thisEndpointPair
isOrdered()
returns thesource()
; otherwise, returns an arbitrary (but consistent) endpoint of the origin edge.
-
nodeV
public final N nodeV()
Returns the nodeadjacent
tonodeU()
along the origin edge. If thisEndpointPair
isOrdered()
, this is equal totarget()
.
-
adjacentNode
public final node)
Returns the node that is adjacent tonode
along the origin edge.- Throws:
- if this
EndpointPair
does not containnode
-
isOrdered
public abstract boolean isOrdered()
Returnstrue
if thisEndpointPair
is an ordered pair (i.e. represents the endpoints of a directed edge).
-
iterator
public final UnmodifiableIterator<N> iterator()
- Specified by:
in interface
<N>
- Returns:
- an Iterator.
-
equals
public abstract boolean obj)
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
.- Overrides:
in class
- Parameters:
obj
- the reference object with which to compare.- Returns:
true
if this object is the same as the obj argument;false
otherwise.- See Also:
- ,
-
hashCode
public abstract int hashCode()
The hashcode of an orderedEndpointPair
is equal toObjects.hashCode(source(), target())
. The hashcode of an unorderedEndpointPair
is equal tonodeU().hashCode() + nodeV().hashCode()
.- Overrides:
in class
- Returns:
- a hash code value for this object.
- See Also:
- ,
-
-