public int compareTo ( Rational other ) { if ( denominator == other . getDenominator ( ) ) { return ( ( Long ) numerator ) . compareTo ( other . getNumerator ( ) ) ; } else { Long adjustedNumerator = numerator * other . getDenominator ( ) ; Long otherAdjustedNumerator = other . getNumerator ( ) * denominator ; return adjustedNumerator . compareTo ( otherAdjustedNumerator ) ; } }
Compares this value with the specified object for order . Returns a negative integer zero or a positive integer as this value is less than equal to or greater than the specified value .