private void addOperator ( final String operator ) { // This should never happen but sanity check... Validate . notNull ( operator ) ; if ( lastOperator == null ) { lastOperator = operator ; } /* Logic to determine whether to put parentheses around the existing fieldtext. This is tied to the use of the * NOT operator as it also adds parentheses. */ if ( not ) { if ( componentCount == 1 ) { fieldTextString . insert ( 0 , "NOT+" ) ; } else { fieldTextString . insert ( 0 , "NOT(" ) . append ( ' ' ) ; } } else if ( ! lastOperator . equals ( operator ) ) { fieldTextString . insert ( 0 , ' ' ) . append ( ' ' ) ; } lastOperator = operator ; fieldTextString . append ( ' ' ) . append ( operator ) . append ( ' ' ) ; }
The first section of the fieldtext manipulation process where the NOTs are handled and the operator is added are common to both binaryOp methods so this method saves us repeating the code .