public static String normalize ( Object expression ) { if ( expression == null ) { return null ; } // If it's a number it's not an expression if ( expression instanceof Number ) { return String . valueOf ( expression ) ; } String replacement ; String conditionStr = StringUtils . mergeToSingleUnderscore ( String . valueOf ( expression ) ) ; Matcher matcher = PATTERN . matcher ( conditionStr ) ; StringBuffer result = new StringBuffer ( conditionStr . length ( ) ) ; while ( matcher . find ( ) ) { if ( OPERATORS . containsKey ( matcher . group ( ) ) ) { replacement = ( String ) OPERATORS . get ( matcher . group ( ) ) ; } else if ( PREDEFINED_VARS . containsKey ( matcher . group ( ) ) ) { replacement = ( String ) PREDEFINED_VARS . get ( matcher . group ( ) ) ; } else { replacement = matcher . group ( ) ; } matcher . appendReplacement ( result , replacement ) ; } matcher . appendTail ( result ) ; return result . toString ( ) ; }
Normalize an expression string replace nice names with their coded values and spaces with _ .