SSJ
V. labo.

umontreal.iro.lecuyer.util
Interface MultiDimComparable<T>

All Known Implementing Classes:
MarkovChainComparable, MarkovChainComparableStop, MarkovChainDouble, MarkovChainDoubleStop

public interface MultiDimComparable<T>

This interface represents an object which can be compared in many dimensions or in many ways. This is very flexible. Objects that are compared may really have a multidimensional behavior, or they may not. For example, an object that contains an array could implement this interface with method compareTo(other, i) used to compare the element of index i from the array.

Another example could be an object representing a person and containing some information on that person. Then, method compareTo could compare different informations (age, height, weight). It can also be used to compare in different ways, like comparing the birth date including the birth year to know who is younger or comparing the birth date without the year to know who will celebrate its next birthday first.

See MultiDimComparator to use these comparisons in algorithms requiring a regular Java Comparator, e.g., the sort method in class Arrays.


Method Summary
 int compareTo(T o, int i)
          Compares objects of type T in the i-th dimension.
 int dimension()
          This method returns the number of dimensions for which the method compareTo can be called for this object.
 

Method Detail

dimension

int dimension()
This method returns the number of dimensions for which the method compareTo can be called for this object. A more formal definition would be the greatest integer such that compareTo can be called for i = 0,…,dimension() - 1.


compareTo

int compareTo(T o,
              int i)
Compares objects of type T in the i-th dimension. This method must return a negative integer, zero, or a positive integer depending on whether the implicit object is less than, equal to, or greater than o, in dimension i. If i is negative or greater than or equal to the value returned by dimension(), then this method should throw an IllegalArgumentException.


SSJ
V. labo.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.