protected Collection < String > normalize ( String string , final boolean tokenize ) { if ( string == null ) { return Collections . emptyList ( ) ; } if ( tokenize ) { final Collection < String > result = new LinkedHashSet <> ( ) ; result . addAll ( normalize ( string , false ) ) ; final Splitter splitter = Splitter . on ( ' ' ) . omitEmptyStrings ( ) ; final List < String > tokens = splitter . splitToList ( string ) ; for ( final String token : tokens ) { final Collection < String > normalizedTokens = normalize ( token , false ) ; result . addAll ( normalizedTokens ) ; } return result ; } else { string = StringUtils . replaceWhitespaces ( string , "" ) ; string = StringUtils . replaceAll ( string , "-" , "" ) ; string = StringUtils . replaceAll ( string , "_" , "" ) ; string = StringUtils . replaceAll ( string , "|" , "" ) ; string = StringUtils . replaceAll ( string , "*" , "" ) ; string = string . toUpperCase ( ) ; if ( string . isEmpty ( ) ) { return Collections . emptyList ( ) ; } final String withoutNumbers = string . replaceAll ( "[0-9]" , "" ) ; if ( withoutNumbers . equals ( string ) || withoutNumbers . isEmpty ( ) ) { return Arrays . asList ( string ) ; } return Arrays . asList ( string , withoutNumbers ) ; } }
Normalizes the incoming string before doing matching