int encodeCEs ( long ces [ ] , int cesLength ) { if ( cesLength < 0 || cesLength > Collation . MAX_EXPANSION_LENGTH ) { throw new IllegalArgumentException ( "mapping to too many CEs" ) ; } if ( ! isMutable ( ) ) { throw new IllegalStateException ( "attempt to add mappings after build()" ) ; } if ( cesLength == 0 ) { // Convenience: We cannot map to nothing, but we can map to a completely ignorable CE. // Do this here so that callers need not do it. return encodeOneCEAsCE32 ( 0 ) ; } else if ( cesLength == 1 ) { return encodeOneCE ( ces [ 0 ] ) ; } else if ( cesLength == 2 ) { // Try to encode two CEs as one CE32. long ce0 = ces [ 0 ] ; long ce1 = ces [ 1 ] ; long p0 = ce0 >>> 32 ; if ( ( ce0 & 0xffffffffff00ff L ) == Collation . COMMON_SECONDARY_CE && ( ce1 & 0xffffffff00ffffff L ) == Collation . COMMON_TERTIARY_CE && p0 != 0 ) { // Latin mini expansion return ( int ) p0 | ( ( ( int ) ce0 & 0xff00 ) << 8 ) | ( ( ( int ) ce1 >> 16 ) & 0xff00 ) | Collation . SPECIAL_CE32_LOW_BYTE | Collation . LATIN_EXPANSION_TAG ; } } // Try to encode two or more CEs as CE32s. int [ ] newCE32s = new int [ Collation . MAX_EXPANSION_LENGTH ] ; // TODO: instance field? for ( int i = 0 ; ; ++ i ) { if ( i == cesLength ) { return encodeExpansion32 ( newCE32s , 0 , cesLength ) ; } int ce32 = encodeOneCEAsCE32 ( ces [ i ] ) ; if ( ce32 == Collation . NO_CE32 ) { break ; } newCE32s [ i ] = ce32 ; } return encodeExpansion ( ces , 0 , cesLength ) ; }
Encodes the ces as either the returned ce32 by itself or by storing an expansion with the returned ce32 referring to that .