se.chalmers.cs.gf.util
Class Pair<A,B>

java.lang.Object
  extended by se.chalmers.cs.gf.util.Pair<A,B>
Type Parameters:
A - The type of the first value.
B - The type of the second value.
All Implemented Interfaces:
java.lang.Comparable<Pair<A,B>>
Direct Known Subclasses:
MapEntryPair

public class Pair<A,B>
extends java.lang.Object
implements java.lang.Comparable<Pair<A,B>>

An immutable 2-tuple. Based on code from Higher-Order Java.


Field Summary
 A fst
          The first component.
 B snd
          The second component.
 
Constructor Summary
Pair(A fst, B snd)
          Creates a new pair.
 
Method Summary
 int compareTo(Pair<A,B> p)
          FIXME: Fails if the element types are not comparable.
 boolean equals(java.lang.Object o)
          Compares this pair to another object for equality.
 int hashCode()
          Returns a hash code for this pair.
static
<A,B> Pair<A,B>
pair(A a, B b)
          Construct a pair.
 java.lang.Object[] toArray()
          Gets an array representation of this pair.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

fst

public final A fst
The first component.


snd

public final B snd
The second component.

Constructor Detail

Pair

public Pair(A fst,
            B snd)
Creates a new pair.

Parameters:
fst - The first component.
snd - The second component.
Method Detail

equals

public boolean equals(java.lang.Object o)
Compares this pair to another object for equality.

Overrides:
equals in class java.lang.Object
Parameters:
o - The object to compare this pair with.
Returns:
true iff o is not null and o is a Pair and the components of this and o are pairwise equal or both null.

hashCode

public int hashCode()
Returns a hash code for this pair. The hash code is calculated from the hash codes of the components.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

compareTo

public int compareTo(Pair<A,B> p)
FIXME: Fails if the element types are not comparable.

Specified by:
compareTo in interface java.lang.Comparable<Pair<A,B>>

toArray

public java.lang.Object[] toArray()
Gets an array representation of this pair.

Returns:
A 2-element array containing the elements of this pair in order.

pair

public static <A,B> Pair<A,B> pair(A a,
                                   B b)
Construct a pair. Convenience method to allow type inference and