Given some {@code Clause}s returns a binary function that forwards the result of
the first clause which condition is true, of an empty {@code Optional} if
no clause matches the condition.
483819
@SafeVarargs
    public static <T, U, R> BiFunction<T, U, Optional<R>> maybeFirstMatch(BinaryClause<T, U, R>... clauses) {
        final List<Clause<Pair<T, U>, R>> unaryClauses = Sequences.of(clauses).map(BinaryClause::tupled).toList();
        return Pairs.untupled(new MaybeFirstMatchStrategy<>(unaryClauses));
    }
24069
@SafeVarargs
    public static <T, U, R> BiFunction<T, U, R> firstMatch(BinaryClause<T, U, R>... clauses) {
        final List<Clause<Pair<T, U>, R>> unaryClauses = Sequences.of(clauses).map(BinaryClause::tupled).toList();
        return Pairs.untupled(new FirstMatchStrategy<>(unaryClauses));
    }
847922
@NotNull
    public Optional<T> filter(@NotNull Predicate<? super T> predicate) {
        if (!isPresent()) return this;
        return predicate.test(value) ? this : Optional.<T>empty();
    }
109293
public static BooleanExpression anyOf(BooleanExpression... exprs) {
        BooleanExpression rv = null;
        for (BooleanExpression b : exprs) {
            rv = rv == null ? b : rv.or(b);
        }
        return rv;
    }
709819
function maybeModifier(predicate) {
        return function () {
          if (!check.defined(arguments[0]) || check.nulled(arguments[0])) {
            return true;
          }
          return predicate.apply(null, arguments);
        };
      }
449524
@SafeVarargs
    public static <T, R> Function<T, List<R>> allMatches(Clause<T, R>... clauses) {
        return new AllMatchesStrategy<>(Arrays.asList(clauses));
    }
1152533
@SafeVarargs
    public static <T, R> Function<T, R> firstMatch(Clause<T, R>... clauses) {
        return new FirstMatchStrategy<>(Arrays.asList(clauses));
    }
134797
@Nullable
    public static Predicate anyOf(Collection<Predicate> exprs) {
        Predicate rv = null;
        for (Predicate b : exprs) {
            if (b != null) {
                rv = rv == null ? b : ExpressionUtils.or(rv,b);
            }
        }
        return rv;
    }
649259
@Beta
    public static <T> Predicate<T> nor(Predicate<? super T> first, Predicate<? super T> second) {
        return com.google.common.base.Predicates.not(com.google.common.base.Predicates.or(first, second));
    }
971167
private static void cleanEmptyLeafs(LogicClause clause)
  {
    if(clause == null || clause.getOp() == LogicClause.Operator.LEAF)
    {
      return;
    }
    
    LinkedList<LogicClause> childListCopy = new LinkedList<>(clause.getChildren());
    
    clause.clearChildren();
    
    ListIterator<LogicClause> itChildren = childListCopy.listIterator();
    while(itChildren.hasNext())
    {
      LogicClause n = itChildren.next();
      
      // don't add empty leafs, add everything else
      if(!(n.getOp() == LogicClause.Operator.LEAF && n.getContent() == null)) 
      {
        clause.addChild(n);
      }
    }
    
    // clean all sub clauses
    for(LogicClause c : clause.getChildren())
    {
      cleanEmptyLeafs(c);
    }
  }
163055
protected static boolean isOperatorFoundInClause(String operator, List<Object> clause) {
        boolean found = false;

        // first check for the existence of $not so that we can find negated operators:
        // if we find $not then recurse with the value associated with it in the query map
        for (Object rawTerm : clause){
            if (rawTerm instanceof Map) {
                Map term = (Map) rawTerm;
                if (term.size() == 1 && term.values().toArray()[0] instanceof Map) {
                    Map predicate = (Map) term.values().toArray()[0];
                    if (predicate.get(NOT) != null && predicate.get(NOT) instanceof Map) {
                        return isOperatorFoundInClause(operator, Collections
                                .<Object>singletonList(predicate));
                    }
                }
            }
        }

        // if we didn't find $not then look directly for the operator
        for (Object rawTerm : clause){
            if (rawTerm instanceof Map) {
                Map term = (Map) rawTerm;
                if (term.size() == 1 && term.values().toArray()[0] instanceof Map) {
                    Map predicate = (Map) term.values().toArray()[0];
                    if (predicate.get(operator) != null) {
                        found = true;
                        break;
                    }
                }
            }
        }

        return found;
    }
747096
public static <A> ConditionalConsequenceBuilder when( Variable<A> var, Predicate1<A> predicate ) {
        return when( FlowDSL.expr( var, predicate ) );
    }
1156727
public static Optional<Condition> createInCondition(final PredicateInRightValue inRightValue, final Column column) {
        List<SQLExpression> sqlExpressions = new LinkedList<>();
        for (ExpressionSegment each : inRightValue.getSqlExpressions()) {
            if (!(each instanceof SimpleExpressionSegment)) {
                sqlExpressions.clear();
                break;
            } else {
                sqlExpressions.add(((SimpleExpressionSegment) each).getSQLExpression());
            }
        }
        return sqlExpressions.isEmpty() ? Optional.<Condition>absent() : Optional.of(new Condition(column, sqlExpressions));
    }
593699
private boolean find(Clause clause, char[] chars, int[] cursor) {
    int start = cursor[0];
    int end = cursor[1];
    while (end - start >= clause.minlen)
      if (matchClause(clause, chars, cursor))
        return true;
      else
        cursor[0] = ++start;
    return false;
  }
1175658
@NotNull
    @Contract(pure = true)
    @SuppressWarnings("unchecked")
    public static <T> Optional<T> empty() {
        return (Optional<T>) EMPTY;
    }
1073638
public Choice<T> condition(final Predicate<? super T> predicate) {
    checkNotNull(predicate);
    final Choice<T> thisChoice = this;
    return new Choice<T>() {
      @Override
      protected Iterator<T> iterator() {
        return Iterators.filter(thisChoice.iterator(), predicate);
      }

      @Override
      public String toString() {
        return String.format("%s.condition(%s)", thisChoice, predicate);
      }
    };
  }
782071
public static <T, R> Function<T, R> doIf(final Predicate<T> condition, final CheckedFunction<T, R> trueFunction,
                                             final CheckedFunction<T, R> falseFunction) {
        return t -> {
            try {
                if (condition.test(t)) {
                    return trueFunction.apply(t);
                }
                return falseFunction.apply(t);
            } catch (final Throwable e) {
                LOGGER.warn(e.getMessage(), e);
                try {
                    return falseFunction.apply(t);
                } catch (final Throwable ex) {
                    throw new IllegalArgumentException(ex.getMessage());
                }
            }
        };
    }