com.twitter.common.collections
Class Pair<A,B>

java.lang.Object
  extended by com.twitter.common.collections.Pair<A,B>
Type Parameters:
A - The type of the 1st item in the pair.
B - The type of the 2nd item in the pair.

public class Pair<A,B>
extends Object

An immutable 2-tuple with value-equals semantics.


Constructor Summary
Pair(A first, B second)
          Creates a new pair.
 
Method Summary
 boolean equals(Object o)
           
static
<S,T> Function<Pair<S,T>,S>
first()
          Creates a function that can extract the first item of pairs of the given type parametrization.
 A getFirst()
           
 B getSecond()
           
 int hashCode()
           
static
<A,B> Pair<A,B>
of(A a, B b)
          Convenience method to create a pair.
static
<S,T> Function<Pair<S,T>,T>
second()
          Creates a function that can extract the second item of pairs of the given type parametrization.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pair

public Pair(@Nullable
            A first,
            @Nullable
            B second)
Creates a new pair.

Parameters:
first - The first value.
second - The second value.
Method Detail

getFirst

@Nullable
public A getFirst()

getSecond

@Nullable
public B getSecond()

equals

public boolean equals(Object o)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

first

public static <S,T> Function<Pair<S,T>,S> first()
Creates a function that can extract the first item of pairs of the given type parametrization.

Type Parameters:
S - The type of the 1st item in the pair.
T - The type of the 2nd item in the pair.
Returns:
A function that will extract the 1st item in a pair.

second

public static <S,T> Function<Pair<S,T>,T> second()
Creates a function that can extract the second item of pairs of the given type parametrization.

Type Parameters:
S - The type of the 1st item in the pair.
T - The type of the 2nd item in the pair.
Returns:
A function that will extract the 2nd item in a pair.

of

public static <A,B> Pair<A,B> of(@Nullable
                                 A a,
                                 @Nullable
                                 B b)
Convenience method to create a pair.

Type Parameters:
A - The type of the 1st item in the pair.
B - The type of the 2nd item in the pair.
Parameters:
a - The first value.
b - The second value.
Returns:
A new pair of [a, b].