info.javelot.functionalj.tuple
Class Pair

java.lang.Object
  extended byinfo.javelot.functionalj.tuple.Pair
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Triple

public class Pair
extends Object
implements Serializable

Used to create a tuple of two objects. Tuples can be used anywhere there is a need to group objects together, and are used by the Tuples.zip(List,List) method.

Author:
Copyright © 2006 Frederic Daoud
See Also:
Serialized Form

Constructor Summary
Pair(Object p_first, Object p_second)
          Creates a tuple of the two given objects.
 
Method Summary
 boolean equals(Object p_object)
          Determines if the given object is equal to this object, by comparing the two objects of each tuple using their respective equals(Object) methods.
 Object getFirst()
          Returns the first object of the tuple.
 Object getSecond()
          Returns the second object of the tuple.
protected  List getStrings()
          Returns a list of the String representations of the objects of the tuple.
 int hashCode()
          Returns the hash code associated with this object.
 String toString()
          Returns a String representation of the Pair.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pair

public Pair(Object p_first,
            Object p_second)
Creates a tuple of the two given objects.

Parameters:
p_first - the first object of the pair. A null value is accepted.
p_second - the second object of the pair. A null value is accepted.
Method Detail

getFirst

public Object getFirst()
Returns the first object of the tuple.

Returns:
the first object of the tuple, which may be null.

getSecond

public Object getSecond()
Returns the second object of the tuple.

Returns:
the second object of the tuple, which may be null.

hashCode

public int hashCode()
Returns the hash code associated with this object.

Thanks to Paul Field for suggesting the improvement on this hash function.

Returns:
the hash code associated with this object, which is calculated by adding together the hash codes of the objects contained in the tuple, multiplying by 31 each time. A null value is considered to have* a hash code of 0. Thus, if this pair contains two null values, this method returns 0.

equals

public boolean equals(Object p_object)
Determines if the given object is equal to this object, by comparing the two objects of each tuple using their respective equals(Object) methods. Corresponding null values are also considered equal.

Parameters:
p_object - the object against which to compare this tuple.
Returns:
true if the pairs contain the same values; false otherwise.

getStrings

protected List getStrings()
Returns a list of the String representations of the objects of the tuple. Subclasses override this method to specify additional objects. The toString() method uses this to construct the String representation of the tuple.

Returns:
a list of the String representations of the objects of the tuple.

toString

public String toString()
Returns a String representation of the Pair.

Returns:
a String representation of the Pair of the form "(String, String)".