com.bpodgursky.jbool_expressions.rules.CombineAnd Maven / Gradle / Ivy
package com.bpodgursky.jbool_expressions.rules;
import com.google.common.collect.Lists;
import com.bpodgursky.jbool_expressions.And;
import com.bpodgursky.jbool_expressions.ExprUtil;
import com.bpodgursky.jbool_expressions.Expression;
import java.util.List;
public class CombineAnd extends Rule, K> {
@Override
public Expression applyInternal(And and) {
for (Expression expr : and.expressions) {
if (expr instanceof And) {
And childAnd = (And) expr;
List> newChildren = Lists.newArrayList();
ExprUtil.addAll(newChildren, ExprUtil.allExceptMatch(and.expressions, childAnd));
ExprUtil.addAll(newChildren, childAnd.expressions);
return And.of(newChildren);
}
}
return and;
}
@Override
protected boolean isApply(Expression input) {
return input instanceof And;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy