com.bpodgursky.jbool_expressions.rules.DeMorgan 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.Expression;
import com.bpodgursky.jbool_expressions.Not;
import com.bpodgursky.jbool_expressions.Or;
import java.util.List;
public class DeMorgan extends Rule, K> {
@Override
public Expression applyInternal(Not not) {
Expression e = not.getE();
if(e instanceof And){
And internal = (And) e;
List> morganed = Lists.newArrayList();
for(Expression expr: internal.expressions){
morganed.add(Not.of(expr));
}
return Or.of(morganed);
}
if(e instanceof Or){
Or internal = (Or) e;
List> morganed = Lists.newArrayList();
for(Expression expr: internal.expressions){
morganed.add(Not.of(expr));
}
return And.of(morganed);
}
return not;
}
@Override
protected boolean isApply(Expression input) {
return input instanceof Not;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy