public class Pair<FirstType extends java.lang.Comparable<? super FirstType>,SecondType extends java.lang.Comparable<? super SecondType>> extends java.lang.Object implements java.lang.Comparable<Pair<FirstType,SecondType>>
KeyValue| Constructor and Description |
|---|
Pair(FirstType first,
SecondType second) |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Pair<FirstType,SecondType> other)
Compares this pair to the other.
|
boolean |
equals(java.lang.Object obj)
Compares this pair to the object, which should be of type
Pair, or otherwise
false is returned. |
FirstType |
first()
Returns the first element, with a shorter method name than
getFirst. |
FirstType |
getFirst()
Returns the first element.
|
SecondType |
getSecond()
Returns the second element.
|
int |
hashCode()
Returns a hash code for the pair.
|
static <X extends java.lang.Comparable<? super X>,Y extends java.lang.Comparable<? super Y>> |
of(X first,
Y second)
Class method that allows inference of the parameterized type.
|
SecondType |
second()
Returns the second element, with a shorter method name than
getSecond~. |
java.lang.String |
toString()
Returns the pair as a string in the form "first, second".
|
public Pair(FirstType first, SecondType second)
first - the first value in the pairsecond - the second value in the pairpublic static <X extends java.lang.Comparable<? super X>,Y extends java.lang.Comparable<? super Y>> Pair<X,Y> of(X first, Y second)
// compare:
Pair<String, Integer> pair = new Pair<String, Integer>("Homer", 34);
Pair<String, Integer> pair = Pair.create("Homer", 34);
X - the type of the first value; must be ComparableY - the type of the second value; must be Comparablefirst - the first value in the pairsecond - the second value in the pairpublic FirstType getFirst()
public SecondType getSecond()
public FirstType first()
getFirst.public SecondType second()
getSecond~.public boolean equals(java.lang.Object obj)
Pair, or otherwise
false is returned.equals in class java.lang.Objectobj - the object to compare to; can be nullpublic int compareTo(Pair<FirstType,SecondType> other)
compareTo in interface java.lang.Comparable<Pair<FirstType extends java.lang.Comparable<? super FirstType>,SecondType extends java.lang.Comparable<? super SecondType>>>other - the other objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object