util
Class Pair<A,B>

java.lang.Object
  extended by util.Pair<A,B>
Type Parameters:
A - The type of the first element of a pair.
B - The type of the second element of a pair.
All Implemented Interfaces:
Serializable

public class Pair<A,B>
extends Object
implements Serializable

A pair of objects of some specified type. Convenient for return values, etc.

See Also:
Serialized Form

Field Summary
 A a
          The first element of the pair.
 B b
          The second element of the pair.
 
Constructor Summary
Pair(A a, B b)
           
 
Method Summary
 boolean equals(Object other)
           
 int hashCode()
           
static
<A,B> Pair<A,B>
of(A a, B b)
          A more readable synonym for pair(A, B).
static
<A,B> Pair<A,B>
pair(A a, B b)
          A convenience method so that the types of the elements don't have to be given explicitly.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

a

public final A a
The first element of the pair.


b

public final B b
The second element of the pair.

Constructor Detail

Pair

public Pair(A a,
            B b)
Parameters:
a - The first element of the pair.
b - The second element of the pair.
Method Detail

pair

public static <A,B> Pair<A,B> pair(A a,
                                   B b)
A convenience method so that the types of the elements don't have to be given explicitly.

Without this method, this would be required to create a Pair:

Pair<Integer, String> stuff =
    new Pair<Integer, String>(42, "spam");

With this method:

Pair<Integer, String> stuff =
    Pair.pair(42, "spam");

Type Parameters:
A - The type of the first element.
B - The type of the second element.
Parameters:
a - The first element of the pair.
b - The second element of the pair.
Returns:
A newly constructed pair.

of

public static <A,B> Pair<A,B> of(A a,
                                 B b)
A more readable synonym for pair(A, B).

Type Parameters:
A - The type of the first element.
B - The type of the second element.
Parameters:
a - The first element of the pair.
b - The second element of the pair.
Returns:
A newly constructed pair.

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object