public class Pair<T1,T2>
extends java.lang.Object
Pair
class.Constructor and Description |
---|
Pair()
A default constructor that sets both fields in this Pair to null.
|
Pair(Pair<T1,T2> p)
A copy constructor.
|
Pair(T1 first,
T2 second)
A constructor that initializes both fields in this pair.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o)
Override the equals() method from the Object class.
|
T1 |
getFirst()
Return a reference to the first element of this pair.
|
T2 |
getSecond()
Return a reference to the second element of this pair.
|
<T> Pair<T,T2> |
replaceFirst(T first)
Create a new Pair object with the given first element and the
same second element as this Pair's second element.
|
<T> Pair<T1,T> |
replaceSecond(T second)
Create a new Pair object with the given second element and the
same first element as this Pair's first element.
|
Pair<T1,T2> |
setFirst(T1 first)
Change this Pair so that its first element is the given element.
|
Pair<T1,T2> |
setSecond(T2 second)
Change this Pair so that its second element is the given element.
|
java.lang.String |
toString()
Create a String representation of this Pair object.
|
Pair<T2,T1> |
transpose()
Create a new Pair object whose first element is a reference
to this object's first element, and whose second element is
a reference to this object's second element.
|
public Pair()
public Pair(Pair<T1,T2> p)
p
- a Pair object to make a (shallow) copy ofpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- Object to compare this Pair object withpublic T1 getFirst()
public T2 getSecond()
public <T> Pair<T,T2> replaceFirst(T first)
first
- first element for the new Pair objectpublic <T> Pair<T1,T> replaceSecond(T second)
second
- second element for the new Pair objectpublic Pair<T1,T2> setFirst(T1 first)
first
- new first element for this Pair objectpublic Pair<T1,T2> setSecond(T2 second)
second
- new second element for this Pair objectpublic java.lang.String toString()
toString
in class java.lang.Object