edu.rice.cs.plt.tuple
Class Pair<T1,T2>

java.lang.Object
  extended by edu.rice.cs.plt.tuple.Tuple
      extended by edu.rice.cs.plt.tuple.Pair<T1,T2>
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
IdentityPair

public class Pair<T1,T2>
extends Tuple

An arbitrary pair of objects; overrides toString(), equals(Object), and Tuple.hashCode().

See Also:
Serialized Form

Field Summary
protected  T1 _first
           
protected  T2 _second
           
 
Constructor Summary
Pair(T1 first, T2 second)
           
 
Method Summary
static
<T1 extends Comparable<? super T1>,T2 extends Comparable<? super T2>>
TotalOrder<Pair<? extends T1,? extends T2>>
comparator()
          Produce a comparator for pairs, ordered by the natural order of the elements (the leftmost elements have the highest sort priority).
static
<T1,T2> TotalOrder<Pair<? extends T1,? extends T2>>
comparator(Comparator<? super T1> comp1, Comparator<? super T2> comp2)
          Produce a comparator for pairs, ordered by the given comparators (the leftmost elements have the highest sort priority).
 boolean equals(Object o)
           
static
<T1,T2> Lambda2<T1,T2,Pair<T1,T2>>
factory()
          Produce a lambda that invokes the constructor.
 T1 first()
           
static
<T> Lambda<Pair<? extends T,?>,T>
firstGetter()
          Produce a lambda that invokes first() on a provided pair.
protected  int generateHashCode()
           
 Pair<T2,T1> inverse()
          Invert a pair.
static
<T1,T2> Lambda<Pair<T1,T2>,Pair<T2,T1>>
inverter()
          Produce a lambda that invokes inverse() on a provided pair.
static
<T1,T2> Pair<T1,T2>
make(T1 first, T2 second)
          Call the constructor (allows the type arguments to be inferred)
 T2 second()
           
static
<T> Lambda<Pair<?,? extends T>,T>
secondGetter()
          Produce a lambda that invokes second() on a provided pair.
 String toString()
           
 
Methods inherited from class edu.rice.cs.plt.tuple.Tuple
hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_first

protected final T1 _first

_second

protected final T2 _second
Constructor Detail

Pair

public Pair(T1 first,
            T2 second)
Method Detail

first

public T1 first()

second

public T2 second()

inverse

public Pair<T2,T1> inverse()
Invert a pair. Subclasses should override this method to create a new pair of the same type.


toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object
Returns:
true iff this is of the same class as o, and each corresponding element is equal (according to equals)

generateHashCode

protected int generateHashCode()
Specified by:
generateHashCode in class Tuple

make

public static <T1,T2> Pair<T1,T2> make(T1 first,
                                       T2 second)
Call the constructor (allows the type arguments to be inferred)


factory

public static <T1,T2> Lambda2<T1,T2,Pair<T1,T2>> factory()
Produce a lambda that invokes the constructor.


inverter

public static <T1,T2> Lambda<Pair<T1,T2>,Pair<T2,T1>> inverter()
Produce a lambda that invokes inverse() on a provided pair.


firstGetter

public static <T> Lambda<Pair<? extends T,?>,T> firstGetter()
Produce a lambda that invokes first() on a provided pair.


secondGetter

public static <T> Lambda<Pair<?,? extends T>,T> secondGetter()
Produce a lambda that invokes second() on a provided pair.


comparator

public static <T1 extends Comparable<? super T1>,T2 extends Comparable<? super T2>> TotalOrder<Pair<? extends T1,? extends T2>> comparator()
Produce a comparator for pairs, ordered by the natural order of the elements (the leftmost elements have the highest sort priority).


comparator

public static <T1,T2> TotalOrder<Pair<? extends T1,? extends T2>> comparator(Comparator<? super T1> comp1,
                                                                             Comparator<? super T2> comp2)
Produce a comparator for pairs, ordered by the given comparators (the leftmost elements have the highest sort priority).