private void handleComparator() {
    if (operator == null) {
      return;
    }

    if (predicates.size() == 0) {
      throw new IllegalStateException("No left operand.");
    }
    Predicate predicate;

    switch (operator) {
      case And:
        predicate = new AndPredicate(predicates.toArray(new Predicate[predicates.size()]));
        break;
      case Or:
        predicate = new OrPredicate(predicates.toArray(new Predicate[predicates.size()]));
        break;
      default:
        throw new IllegalStateException("Unknown operator " + this.operator);
    }
    predicates.clear();
    addPredicate(predicate);
  }
Allow for chaining of already constructed predicates
ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PredicateBuilder.java