com.bpodgursky.jbool_expressions.ExprUtil Maven / Gradle / Ivy
package com.bpodgursky.jbool_expressions;
import java.util.*;
public class ExprUtil {
public static Expression[] allExceptMatch(Expression[] exprs, Expression omit){
Set> andTerms = new HashSet>();
for(Expression eachExpr: exprs){
if(!eachExpr.equals(omit)){
andTerms.add(eachExpr);
}
}
int i = 0;
Expression[] result = expr(andTerms.size());
for(Expression expr: andTerms){
result[i++] = expr;
}
return result;
}
@SuppressWarnings("unchecked")
public static Expression[] expr(int length){
return new Expression[length];
}
public static void addAll(Collection> set, Expression[] values){
Collections.addAll(set, values);
}
@SuppressWarnings("unchecked")
public static List> list(Expression... exprs){
return Arrays.>asList(exprs);
}
public static Set getVariables(Expression expr){
if(expr instanceof Variable){
return Collections.singleton(((Variable) expr).getValue());
}else if(expr instanceof Not){
return getVariables(((Not) expr).getE());
}else if(expr instanceof NExpression){
Set vars = new HashSet();
for(Expression child: ((NExpression)expr).expressions){
vars.addAll(getVariables(child));
}
return vars;
}
return Collections.emptySet();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy