edu.stanford.nlp.util
Class Pair

java.lang.Object
  |
  +--edu.stanford.nlp.util.Pair
All Implemented Interfaces:
Comparable, Serializable
Direct Known Subclasses:
ScoredPair, UnorderedPair

public class Pair
extends Object
implements Comparable, Serializable

Pair: A Class for holding a pair of objects.

See Also:
Serialized Form

Field Summary
 Object first
          Direct access is deprecated.
 Object second
          Direct access is deprecated.
 
Constructor Summary
Pair()
           
Pair(Object first, Object second)
           
 
Method Summary
 int compareTo(Object o)
          Compares this Pair to another object.
 boolean equals(Object o)
           
 Object first()
           
 int hashCode()
           
 void read(InDataStreamFile in)
          Read a string representation of a Pair from a DataStream.
 void save(OutDataStreamFile out)
          Write a string representation of a Pair from a DataStream.
 Object second()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

first

public Object first
Direct access is deprecated. Use first().


second

public Object second
Direct access is deprecated. Use second().

Constructor Detail

Pair

public Pair()

Pair

public Pair(Object first,
            Object second)
Method Detail

first

public Object first()

second

public Object second()

toString

public String toString()
Overrides:
toString in class Object

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

read

public void read(InDataStreamFile in)
Read a string representation of a Pair from a DataStream. This might not work correctly unless the pair of objects are of type String.


save

public void save(OutDataStreamFile out)
Write a string representation of a Pair from a DataStream. The toString() method is called on each of the pair of objects and a String representation is written. This might not allow one to recover the pair of objects unless they are of type String.


compareTo

public int compareTo(Object o)
Compares this Pair to another object. If the object is a Pair, this function will work providing the elements of the Pair are themselves comparable. It will then return a value based on the pair of objects, where p > q iff p.first() > q.first() || (p.first().equals(q.first()) && p.second() > q.second()). If the other object is not a Pair, it throws a ClassCastException.

Specified by:
compareTo in interface Comparable
Parameters:
o - the Object to be compared.
Returns:
the value 0 if the argument is a Pair equal to this Pair; a value less than 0 if the argument is a Pair greater than this Pair; and a value greater than 0 if the argument is a Pair less than this Pair.
Throws:
ClassCastException - if the argument is not a Pair.
See Also:
Comparable


Stanford NLP Group