SUMMARY: MODULE | CLASS | TYPE | PROC | VAR | CONST | DETAIL: TYPE | PROC | VAR | CONST

# ADT:Comparator

Note: The class Comparator is modeled after from Java class ``java.util.Comparator`', from which the documentation is also derived.

### Import List

        Object
        Object
        RT0

Class List
Comparator |
String |

Class Summary: Comparator [Detail]
      +---RT0.Object
           |
           +---Object.Object
                |
                +--ADT:Comparator.Comparator
Method Summary
Compare(Object, Object): LONGINT Compares its two arguments for order.
Inherited Methods
From RT0.Object: Finalize From Object.Object: Equals, HashCode, ToString

Class Summary: String [Detail]
      +---RT0.Object
           |
           +---Object.Object
                |
                +---ADT:Comparator.Comparator
                     |
                     +--ADT:Comparator.String
Method Summary
Compare(Object, Object): LONGINT Compares its two arguments for order.
Inherited Methods
From RT0.Object: Finalize From Object.Object: Equals, HashCode, ToString From ADT:Comparator.Comparator: Compare

Class Detail: Comparator

Method Detail

### Compare

    PROCEDURE (cmp: Comparator) Compare(o1: Object;
                      o2: Object): LONGINT

> Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

> The implementor must ensure that ``sgn(Compare(x, y)) = -sgn(Compare(y, x))`' for all ``x`' and ``y`'. (This implies that ``Compare(x, y)`' must throw an exception if and only if ``Compare(y, x)`' throws an exception.)

> The implementor must also ensure that the relation is transitive: ``((Compare(x, y)>0) & (Compare(y, z)>0))`' implies ``Compare(x, z)>0`'.

> Finally, the implementer must ensure that ``Compare(x, y)=0`' implies that ``sgn(Compare(x, z))==sgn(Compare(y, z))`' for all ``z`'.

> It is generally the case, but not strictly required that ``(Compare(x, y)==0) == (x.Equals(y))`'. Generally speaking, any comparator that violates this condition should clearly indicate this fact. The recommended language is "Note: this comparator imposes orderings that are inconsistent with ``Equals()`'."

Class Detail: String

Method Detail

### Compare

    PROCEDURE (cmp: String) Compare(o1: Object;
                      o2: Object): LONGINT

> Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

> The implementor must ensure that ``sgn(Compare(x, y)) = -sgn(Compare(y, x))`' for all ``x`' and ``y`'. (This implies that ``Compare(x, y)`' must throw an exception if and only if ``Compare(y, x)`' throws an exception.)

> The implementor must also ensure that the relation is transitive: ``((Compare(x, y)>0) & (Compare(y, z)>0))`' implies ``Compare(x, z)>0`'.

> Finally, the implementer must ensure that ``Compare(x, y)=0`' implies that ``sgn(Compare(x, z))==sgn(Compare(y, z))`' for all ``z`'.

> It is generally the case, but not strictly required that ``(Compare(x, y)==0) == (x.Equals(y))`'. Generally speaking, any comparator that violates this condition should clearly indicate this fact. The recommended language is "Note: this comparator imposes orderings that are inconsistent with ``Equals()`'."

> [Description inherited from Compare]

> Redefines: Compare