public int compareTo ( UnicodeSet o , ComparisonStyle style ) { if ( style != ComparisonStyle . LEXICOGRAPHIC ) { int diff = size ( ) - o . size ( ) ; if ( diff != 0 ) { return ( diff < 0 ) == ( style == ComparisonStyle . SHORTER_FIRST ) ? - 1 : 1 ; } } int result ; for ( int i = 0 ; ; ++ i ) { if ( 0 != ( result = list [ i ] - o . list [ i ] ) ) { // if either list ran out, compare to the last string if ( list [ i ] == HIGH ) { if ( strings . isEmpty ( ) ) return 1 ; String item = strings . first ( ) ; return compare ( item , o . list [ i ] ) ; } if ( o . list [ i ] == HIGH ) { if ( o . strings . isEmpty ( ) ) return - 1 ; String item = o . strings . first ( ) ; int compareResult = compare ( item , list [ i ] ) ; return compareResult > 0 ? - 1 : compareResult < 0 ? 1 : 0 ; // Reverse the order. } // otherwise return the result if even index, or the reversal if not return ( i & 1 ) == 0 ? result : - result ; } if ( list [ i ] == HIGH ) { break ; } } return compare ( strings , o . strings ) ; }
Compares UnicodeSets in three different ways .