private static String [ ] tokenize ( String string ) { if ( string . indexOf ( "?" ) == - 1 && string . indexOf ( "*" ) == - 1 ) { return new String [ ] { string } ; } char [ ] textArray = string . toCharArray ( ) ; List < String > tokens = new ArrayList < String > ( ) ; StringBuilder tokenBuilder = new StringBuilder ( ) ; for ( int i = 0 ; i < textArray . length ; i ++ ) { if ( textArray [ i ] != ' ' && textArray [ i ] != ' ' ) { // collect non wild card characters tokenBuilder . append ( textArray [ i ] ) ; continue ; } if ( tokenBuilder . length ( ) != 0 ) { tokens . add ( tokenBuilder . toString ( ) ) ; tokenBuilder . setLength ( 0 ) ; } if ( textArray [ i ] == ' ' ) { tokens . add ( "?" ) ; } else if ( tokens . size ( ) == 0 || ( i > 0 && tokens . get ( tokens . size ( ) - 1 ) . equals ( "*" ) == false ) ) { tokens . add ( "*" ) ; } } if ( tokenBuilder . length ( ) != 0 ) { tokens . add ( tokenBuilder . toString ( ) ) ; } return ( String [ ] ) tokens . toArray ( new String [ tokens . size ( ) ] ) ; }
Splits a string into a number of tokens .