private static List < String > tokeniseOnLowercaseToUppercase ( String name ) { List < String > splits = new ArrayList <> ( ) ; // the following stores data in pairs (start, finish, start, ...) ArrayList < Integer > candidateBoundaries = new ArrayList <> ( ) ; // now process the array looking for boundaries for ( Integer index = 0 ; index < name . length ( ) ; index ++ ) { if ( index == 0 ) { // the first character is always a boundary candidateBoundaries . add ( index ) ; } else { if ( Character . isUpperCase ( name . codePointAt ( index ) ) && Character . isLowerCase ( name . codePointAt ( index - 1 ) ) ) { candidateBoundaries . add ( index - 1 ) ; candidateBoundaries . add ( index ) ; } } // now check whether this is the terminal character. // and record it to give us the final boundary if ( index == name . length ( ) - 1 ) { candidateBoundaries . add ( index ) ; } } if ( candidateBoundaries . size ( ) % 2 == 1 ) { LOGGER . warn ( "Odd number of boundaries found for: \"{}\"" , name ) ; } for ( int i = 0 ; i < candidateBoundaries . size ( ) ; i += 2 ) { splits . add ( name . substring ( candidateBoundaries . get ( i ) , candidateBoundaries . get ( i + 1 ) + 1 ) ) ; } return splits ; }
Provides a naive camel case splitter to work on character only string .