Package org.jgrapht.alg.util
Class Pair<A,B>
- java.lang.Object
-
- org.jgrapht.alg.util.Pair<A,B>
-
- Type Parameters:
A
- the first element typeB
- the second element type
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
UnorderedPair
public class Pair<A,B> extends java.lang.Object implements java.io.Serializable
Generic pair.Although the instances of this class are immutable, it is impossible to ensure that the references passed to the constructor will not be modified by the caller.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected A
first
The first pair elementprotected B
second
The second pair elementprivate static long
serialVersionUID
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
A
getFirst()
Get the first element of the pairB
getSecond()
Get the second element of the pair<E> boolean
hasElement(E e)
Assess if this pair contains an element.int
hashCode()
static <A,B>
Pair<A,B>of(A a, B b)
Creates new pair of elements pulling of the necessity to provide corresponding types of the elements supplied.java.lang.String
toString()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
first
protected final A first
The first pair element
-
second
protected final B second
The second pair element
-
-
Method Detail
-
getFirst
public A getFirst()
Get the first element of the pair- Returns:
- the first element of the pair
-
getSecond
public B getSecond()
Get the second element of the pair- Returns:
- the second element of the pair
-
hasElement
public <E> boolean hasElement(E e)
Assess if this pair contains an element.- Type Parameters:
E
- the element type- Parameters:
e
- The element in question- Returns:
- true if contains the element, false otherwise
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
of
public static <A,B> Pair<A,B> of(A a, B b)
Creates new pair of elements pulling of the necessity to provide corresponding types of the elements supplied.- Type Parameters:
A
- the first element typeB
- the second element type- Parameters:
a
- first elementb
- second element- Returns:
- new pair
-
-