@SuppressWarnings({ "rawtypes", "unchecked" })
public static Set findFreeVars(Policy policy, Set free_vars){
if (policy instanceof VariableImpl) {
VariableImpl temp = (VariableImpl) policy;
free_vars.add(temp.getVariable());
}
else if (policy == FalseImpl.getInstance()){
//nothing added
}
else if (policy ==TrueImpl.getInstance()){
//nothing added
}
else if(policy instanceof NegationImpl){
NegationImpl temp = (NegationImpl) policy;
findFreeVars(temp.getPolicy(), free_vars);
}
else if (policy instanceof ConjunctionImpl){
ConjunctionImpl temp = (ConjunctionImpl) policy;
Set temp_setA = findFreeVars(temp.getPolicyA(), new HashSet<Object>());
Set temp_setB = findFreeVars(temp.getPolicyB(), new HashSet<Object>());
free_vars.addAll(temp_setA);
free_vars.addAll(temp_setB);
}
else if (policy instanceof DisjunctionImpl){
DisjunctionImpl temp = (DisjunctionImpl) policy;
Set temp_setA = findFreeVars(temp.getPolicyA(), new HashSet<Object>());
Set temp_setB = findFreeVars(temp.getPolicyB(), new HashSet<Object>());
free_vars.addAll(temp_setA);
free_vars.addAll(temp_setB);
}
else if (policy instanceof BoxImpl){
BoxImpl temp = (BoxImpl) policy;
findFreeVars(temp.getPolicy(), free_vars);
}
else if (policy instanceof DiamondImpl){
DiamondImpl temp = (DiamondImpl) policy;
free_vars = findFreeVars(temp.getPolicy(), free_vars);
}
else if (policy instanceof BindImpl){
BindImpl temp = (BindImpl) policy;
findFreeVars(temp.getPolicy(), free_vars);
free_vars.remove(temp.getVariable());
}
else if (policy instanceof AtImpl){
AtImpl temp = (AtImpl) policy;
findFreeVars(temp.getPolicy(), free_vars);
free_vars.add(temp.getVariable());
}
return free_vars;
}