edu.umd.cfar.lamp.viper.util
Class Pair

java.lang.Object
  extended byedu.umd.cfar.lamp.viper.util.Pair
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Triple

public class Pair
extends java.lang.Object
implements java.io.Serializable

Simple object that replicate's c++'s stl pair facility. Often useful to subclass with object specific features. Probably not included in java.util because it tends to encourage instance-heavy programming, while c++'s pair is often optimized out by the compiler.

Author:
davidm
See Also:
Serialized Form

Constructor Summary
Pair(java.lang.Object first, java.lang.Object second)
          Creates a new instance of Pair
 
Method Summary
 boolean equals(java.lang.Object obj)
          Uses first and second's .equals methods.
 java.lang.Object getFirst()
          Returns the object passed as the first argument to the constructor.
 java.lang.Object getSecond()
          Returns the object passed as the second argument to the constructor.
 int hashCode()
          Gets a hashcode for the pair.
 java.lang.String toString()
          Prints the pair as (first, second).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pair

public Pair(java.lang.Object first,
            java.lang.Object second)
Creates a new instance of Pair

Parameters:
first - the first element of the pair
second - the second element of the pair
Method Detail

toString

public java.lang.String toString()
Prints the pair as (first, second).

Returns:
String representation of the data.

hashCode

public int hashCode()
Gets a hashcode for the pair. Uses the same xor algorithm as defined for java.util.Map.Entry.

Returns:
first.hash ^ second.hash, basically

equals

public boolean equals(java.lang.Object obj)
Uses first and second's .equals methods.

Parameters:
obj - the object to compare with
Returns:
true if respective elements in both Pairs are reported as equal.

getFirst

public java.lang.Object getFirst()
Returns the object passed as the first argument to the constructor.

Returns:
the first argument to the constructor

getSecond

public java.lang.Object getSecond()
Returns the object passed as the second argument to the constructor.

Returns:
the second argument to the constructor