net.innig.util
Class OrderedType

java.lang.Object
  extended by net.innig.util.EnumeratedType
      extended by net.innig.util.OrderedType
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public abstract class OrderedType
extends EnumeratedType
implements java.lang.Comparable

An enumerated type with a natural ordering.

Maturity: This class is relatively new. It looks great in unit testing, but hasn't seen real-world use yet.
Plans: Perhaps add JDO support.

Version:
[Development version]
Author:
Paul Cantrell
See Also:
Serialized Form

Constructor Summary
OrderedType(java.lang.String name)
          Creates a new enumerated type, ordered relative to its peers according to its lexical order in the source code.
OrderedType(java.lang.String name, java.lang.Comparable order)
          Creates a new enumerated type, ordered relative to its peers of the same class by a comparable object.
OrderedType(java.lang.String name, int order)
          Creates a new enumerated type, ordered relative to its peers of the same class by an integer.
 
Method Summary
static java.util.SortedSet allTypeNamesSorted(java.lang.Class orderedTypeClass)
          Returns the set of valid type names for the given enumerated type class, in the type's (not the names') natural order.
static java.util.SortedSet allTypesSorted(java.lang.Class orderedTypeClass)
          Returns the ordered set of valid types for the given enumerated type class.
static java.util.Comparator comparator(java.lang.Class orderedTypeClass)
          Returns the comparator which gives the natural ordering on the given class.
 int compareTo(java.lang.Object that)
           
 boolean greaterThan(OrderedType that)
           
 boolean greaterThanEq(OrderedType that)
           
 boolean lessThan(OrderedType that)
           
 boolean lessThanEq(OrderedType that)
           
static java.util.Comparator nameComparator(java.lang.Class orderedTypeClass)
          Returns a comparator which orders Strings by the natural ordering of their corresponding ordered types in the given class.
 
Methods inherited from class net.innig.util.EnumeratedType
allTypeNames, allTypes, equals, getName, hashCode, resolveFromName, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OrderedType

public OrderedType(java.lang.String name)
Creates a new enumerated type, ordered relative to its peers according to its lexical order in the source code. If any of the ordered types of a given class use this constructor, all must use it.


OrderedType

public OrderedType(java.lang.String name,
                   int order)
Creates a new enumerated type, ordered relative to its peers of the same class by an integer. If any of the ordered types of a given class use this constructor, all must use it.


OrderedType

public OrderedType(java.lang.String name,
                   java.lang.Comparable order)
Creates a new enumerated type, ordered relative to its peers of the same class by a comparable object. The comparable object must be immutable and mutually comparable to the order objects assigned to other enumerated types of the same class.

Method Detail

allTypesSorted

public static java.util.SortedSet allTypesSorted(java.lang.Class orderedTypeClass)
Returns the ordered set of valid types for the given enumerated type class.

Throws:
java.lang.IllegalArgumentException - if the given class is not a subclass of OrderedType.

allTypeNamesSorted

public static java.util.SortedSet allTypeNamesSorted(java.lang.Class orderedTypeClass)
Returns the set of valid type names for the given enumerated type class, in the type's (not the names') natural order.

Throws:
java.lang.IllegalArgumentException - if the given class is not a subclass of OrderedType.

comparator

public static java.util.Comparator comparator(java.lang.Class orderedTypeClass)
Returns the comparator which gives the natural ordering on the given class.


nameComparator

public static java.util.Comparator nameComparator(java.lang.Class orderedTypeClass)
Returns a comparator which orders Strings by the natural ordering of their corresponding ordered types in the given class.


compareTo

public final int compareTo(java.lang.Object that)
Specified by:
compareTo in interface java.lang.Comparable

greaterThan

public final boolean greaterThan(OrderedType that)

greaterThanEq

public final boolean greaterThanEq(OrderedType that)

lessThan

public final boolean lessThan(OrderedType that)

lessThanEq

public final boolean lessThanEq(OrderedType that)