@Override
public Tuple<Collection<BasicOperator>, Collection<BasicOperator>> transformOperatorGraph(
final Map<String, BasicOperator> mso,
final BasicOperator rootOperator) {
final GenerateAddEnv genAdd = (GenerateAddEnv) mso.get("genAdd");
final Projection projection = (Projection) mso.get("projection");
final Object[] projVars = projection.getProjectedVariables().toArray();
final Object[] subst = genAdd.getConstants().keySet().toArray();
for (int i = 0; i < subst.length; i++) {
if (!arrayContains(projVars, (Variable) subst[i])) {
genAdd.getConstants().remove(subst[i]);
}
}
final LinkedList<BasicOperator> pres = (LinkedList<BasicOperator>) genAdd
.getPrecedingOperators();
final LinkedList<OperatorIDTuple> succs = (LinkedList<OperatorIDTuple>) projection
.getSucceedingOperators();
final int index = genAdd.getOperatorIDTuple(projection).getId();
BasicOperator pre;
for (int i = 0; i < pres.size(); i++) {
pre = pres.get(i);
pre.addSucceedingOperator(new OperatorIDTuple(projection, index));
pre.removeSucceedingOperator(genAdd);
projection.addPrecedingOperator(pre);
}
projection.removePrecedingOperator(genAdd);
projection.setSucceedingOperator(new OperatorIDTuple(genAdd, 0));
genAdd.setPrecedingOperator(projection);
genAdd.setSucceedingOperators(succs);
BasicOperator succ;
for (int i = 0; i < succs.size(); i++) {
succ = succs.get(i).getOperator();
succ.addPrecedingOperator(genAdd);