private String infixToPostFix(final CustomTokenizer tokenizer) {
    final String space = " ";
    StringBuffer postfix = new StringBuffer();

    Stack<Object> stack = new Stack<>();

    while (tokenizer.hasMoreTokens()) {
      String token = tokenizer.nextToken();

      boolean inText = (token.startsWith("'") && (!token.endsWith("'"))) || (token.startsWith("\"") && (!token.endsWith("\"")));
      String quoteChar = token.substring(0, 1);
      if (inText) {
        while (inText && tokenizer.hasMoreTokens()) {
          token = token + " " + tokenizer.nextToken();
          inText = !(token.endsWith(quoteChar));
        }
      }

      if ("(".equals(token)) {
        // recurse
        postfix.append(infixToPostFix(tokenizer));
        postfix.append(space);
      } else if (")".equals(token)) {
        // exit recursion level
        while (stack.size() > 0) {
          postfix.append(stack.pop().toString());
          postfix.append(space);
        }

        return postfix.toString();
      } else if (isOperand(token)) {
        postfix.append(token);
        postfix.append(space);
      } else {
        // operator..
        // peek the stack..if the top element has a lower precedence than token
        // (peeked + has lower precedence than token *),
        // push token onto the stack
        // otherwise, pop top element off stack and add to postfix string
        // in a loop until lower precedence or empty..then push token
        if (stack.size() > 0) {

          String peek = stack.peek().toString();

          if (precedes(peek, token)) {
            stack.push(token);
          } else {
            boolean bypass = false;

            do {
              if ((stack.size() > 0) && !precedes(stack.peek().toString(), token)) {
                postfix.append(stack.pop().toString());
                postfix.append(space);
              } else {
                bypass = true;
              }
            } while (!bypass);

            stack.push(token);
          }
        } else {
          stack.push(token);
        }
      }
    }

    while (stack.size() > 0) {
      postfix.append(stack.pop().toString());
      postfix.append(space);
    }

    return postfix.toString();
  }
convert in-fix expression to post-fix.

@param tokenizer tokenizer.
@return post-fix expression.
olv-core/src/main/java/pl/otros/logview/accept/query/org/apache/log4j/rule/InFixToPostFix.java