public static int compare ( Term self , Term other ) { // Sanity check. if ( self == null || other == null ) { throw new NullPointerException ( ) ; } // Identical objects are always equal. if ( self == other ) { return 0 ; } // Easy case is when they are not the same type of term. if ( self . isKey ( ) != other . isKey ( ) ) { return ( self . isKey ( ) ) ? 1 : - 1 ; } // Compare the underlying values. try { if ( self . isKey ( ) ) { return self . getKey ( ) . compareTo ( other . getKey ( ) ) ; } else { return self . getIndex ( ) . compareTo ( other . getIndex ( ) ) ; } } catch ( InvalidTermException consumed ) { // This statement can never be reached because both objects are // either keys or indexes. This try/catch block is only here to make // the compiler happy. assert ( false ) ; return 0 ; } }
A utility method to allow the comparison of any two terms .