com.bpodgursky.jbool_expressions.rules.ToSOP 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 com.bpodgursky.jbool_expressions.Or;
import java.util.List;
public class ToSOP extends Rule, K> {
@Override
public Expression applyInternal(And and) {
// if there are any children which are ORs,
for (Expression e : and.expressions) {
if (e instanceof Or) {
Or or = (Or) e;
Expression[] childrenNew = ExprUtil.allExceptMatch(and.expressions, or);
List> newChildren = Lists.newArrayList();
// for each child of the or, we want it AND all other children of the and
for (Expression orChild : or.expressions) {
List> andOthers = Lists.newArrayList();
ExprUtil.addAll(andOthers, childrenNew);
andOthers.add(orChild);
newChildren.add(And.of(andOthers));
}
return Or.of(newChildren);
}
}
return and;
}
@Override
protected boolean isApply(Expression input) {
return input instanceof And;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy