iglu.util
Class ObjectValuePair

java.lang.Object
  |
  +--iglu.util.ObjectValuePair
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class ObjectValuePair
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable

A mapping of an object to some value or score. Since this class is Comparable, it can be used in conjunction with a SortedSet or sorted array to keep objects in order of decreasing values.

Version:
1.0
Author:
Ryan Scherle rscherle@acm.org
See Also:
Serialized Form

Field Summary
private  java.lang.Object object
           
private  java.lang.Object value
           
 
Constructor Summary
ObjectValuePair(java.lang.Object object, double value)
          Constructs a pair.
ObjectValuePair(java.lang.Object object, java.lang.Object value)
          Constructs a pair.
 
Method Summary
 int compareTo(java.lang.Object obj)
          Compares this object to another object.
 int compareTo(ObjectValuePair obj)
          Compares this object to another object.
 java.lang.Object getObject()
          Returns the object from this pair.
 java.lang.Object getValue()
          Returns the value from this pair.
static void main(java.lang.String[] args)
          Runs some tests on this class.
 void setValue(java.lang.Object value)
          Changes the value for this object.
 java.lang.String toString()
          Returns the string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

object

private java.lang.Object object

value

private java.lang.Object value
Constructor Detail

ObjectValuePair

public ObjectValuePair(java.lang.Object object,
                       java.lang.Object value)
Constructs a pair.


ObjectValuePair

public ObjectValuePair(java.lang.Object object,
                       double value)
Constructs a pair.

Method Detail

getObject

public java.lang.Object getObject()
Returns the object from this pair.


getValue

public java.lang.Object getValue()
Returns the value from this pair.


setValue

public void setValue(java.lang.Object value)
Changes the value for this object.


compareTo

public int compareTo(java.lang.Object obj)
Compares this object to another object. ObjectValuePairs are only comparable to other ObjectValuePairs, so passing any other type of object to this method will result in a ClassCastException.

Specified by:
compareTo in interface java.lang.Comparable

compareTo

public int compareTo(ObjectValuePair obj)
Compares this object to another object. The comparison is made based on the value associated with the object, larger values being earlier in the ordering. If two objects have the same value, or if they are not Comparable, they are compared alphabetically based on their string representations. Therefore, this method consideres objects to be equal if their values are equal and their string representations are equal.


toString

public java.lang.String toString()
Returns the string representation of the object.

Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
Runs some tests on this class.