from abc import ABC, abstractmethod from typing import TypeVar, Generic, Any T=TypeVar("T") class Comparator(Generic[T]): @abstractmethod def compare(self, o1:T, o2:T)-> int: ''' 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 {@code sgn(compare(x, y)) == -sgn(compare(y, x))} for all {@code x} and {@code y}. (This implies that {@code compare(x, y)} must throw an exception if and only if {@code compare(y, x)} throws an exception.)

The implementor must also ensure that the relation is transitive: {@code ((compare(x, y)>0) && (compare(y, z)>0))} implies {@code compare(x, z)>0}.

Finally, the implementor must ensure that {@code compare(x, y)==0} implies that {@code sgn(compare(x, z))==sgn(compare(y, z))} for all {@code z}.

It is generally the case, but not strictly required that {@code (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."

In the foregoing description, the notation {@code sgn(}expression{@code )} designates the mathematical signum function, which is defined to return one of {@code -1}, {@code 0}, or {@code 1} according to whether the value of expression is negative, zero, or positive, respectively. @param o1 the first object to be compared. @param o2 the second object to be compared. @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. @raises ValueError if an argument is null and this comparator does not permit null arguments @raises ClassCastException if the arguments' types prevent them from being compared by this comparator. ''' pass class DefaultComparator(Comparator[Any]): def compare(self, o1:Any, o2:Any)-> int: return -1 if o1o2 else 0