util
Class Pair

java.lang.Object
  |
  +--util.Pair
All Implemented Interfaces:
Cloneable, Comparable, Serializable, Speakable

public class Pair
extends Object
implements Cloneable, Comparable, Serializable, Speakable

A utility container that represents a pair of Serializable objects o1 and o2 such that pair( o1, o2 ) == [ o1, o2 ].

See Also:
Cloneable, Comparable, Serializable, Speakable, Serialized Form

Field Summary
protected  Serializable sObj1
          The first object
protected  Serializable sObj2
          The second object
 
Constructor Summary
Pair()
          Creates a new Pair instance with null as both objects.
Pair(Serializable s1, Serializable s2)
          Creates a new Pair instance.
 
Method Summary
 int compareTo(Object oObj)
          Compares this object with the specified object for order.
 boolean equals(Object oObj)
          Returns true if this object is equal to the given object.
 Serializable first()
          Returns the first object.
 int hashCode()
          Returns a hash code value for the object.
 Serializable second()
          Returns the second object.
 Serializable setFirst(Serializable sNew)
          Sets the first serializable object in this pair to a given value.
 Serializable setSecond(Serializable sNew)
          Sets the second serializable object in this pair to a given value.
 void swap()
          Swaps the two serializable objects in this pair, such that [ o1, o2 ] becomes [ o2, o1 ] for all possible values of o1 and o2.
 String toSpeech()
          Returns a speakable string representation of this.
 String toString()
          Returns a string representation of this.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

sObj1

protected Serializable sObj1
The first object

sObj2

protected Serializable sObj2
The second object
Constructor Detail

Pair

public Pair()
Creates a new Pair instance with null as both objects.

Pair

public Pair(Serializable s1,
            Serializable s2)
Creates a new Pair instance.
Parameters:
s1 - a Serializable value
s2 - a Serializable value
Method Detail

first

public Serializable first()
Returns the first object.
Returns:
a Serializable value

second

public Serializable second()
Returns the second object.
Returns:
a Serializable value

toString

public String toString()
Returns a string representation of this.
Overrides:
toString in class Object
Returns:
a String value

toSpeech

public String toSpeech()
Returns a speakable string representation of this.
Specified by:
toSpeech in interface Speakable
Returns:
a String value

equals

public boolean equals(Object oObj)
Returns true if this object is equal to the given object.
Overrides:
equals in class Object
Parameters:
oObj - an Object value
Returns:
a boolean value

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.
Overrides:
hashCode in class Object
Returns:
an int value

compareTo

public int compareTo(Object oObj)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Specified by:
compareTo in interface Comparable
Parameters:
oObj - an Object value
Returns:
an int value

setFirst

public Serializable setFirst(Serializable sNew)
Sets the first serializable object in this pair to a given value. Returns the previous first value.
Parameters:
sNew - a Serializable value
Returns:
a Serializable value of the previous first value.

setSecond

public Serializable setSecond(Serializable sNew)
Sets the second serializable object in this pair to a given value. Returns the previous second value.
Parameters:
sNew - a Serializable value
Returns:
a Serializable value of the previous second value.

swap

public void swap()
Swaps the two serializable objects in this pair, such that [ o1, o2 ] becomes [ o2, o1 ] for all possible values of o1 and o2.