net.aavalla.utils.general
Class UniqueComparable<T extends java.lang.Comparable>

java.lang.Object
  extended by net.aavalla.utils.general.UniqueComparable<T>
All Implemented Interfaces:
java.lang.Comparable<UniqueComparable<T>>

public final class UniqueComparable<T extends java.lang.Comparable>
extends java.lang.Object
implements java.lang.Comparable<UniqueComparable<T>>

Wrapper for an object 'value' implementing Comparable interface. UniqueComparable's compareTo() returns the result of the underlying value object's compareTo() except if it would return 0. In that case UniqueComparable's compareTo() compares the age of the objects. The only time UniqueComparable's compareTo() ever returns 0, is if the UniqueComparable objects are actually the same object. The idea is that values can be ordered and kept unique. This way, for example, an OrderedSet can hold objects with equal values while keeping consistent with equals(). Immutable. Thread-safe.

Author:
Lari Natri

Constructor Summary
UniqueComparable(T value)
          Constructor
 
Method Summary
 int compareTo(UniqueComparable<T> o)
           
 T value()
          Returns the value held.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UniqueComparable

public UniqueComparable(T value)
Constructor

Parameters:
value - value to hold
Throws:
java.lang.NullPointerException - Thrown, if trying to add null value
Method Detail

value

public final T value()
Returns the value held.

Returns:
value

compareTo

public final int compareTo(UniqueComparable<T> o)
Specified by:
compareTo in interface java.lang.Comparable<UniqueComparable<T extends java.lang.Comparable>>