private boolean _checkPrivate0(BasicOperator _op) {
    if (_op.getClass() != lupos.engine.operators.singleinput.Filter.class) {
      return false;
    }

    this.f = (lupos.engine.operators.singleinput.Filter) _op;

    List<BasicOperator> _precedingOperators_1_0 = _op.getPrecedingOperators();

    this._dim_0 = -1;
    this.o1 = new lupos.engine.operators.BasicOperator[_precedingOperators_1_0.size()];

    for (BasicOperator _precOp_1_0 : _precedingOperators_1_0) {
      this._dim_0 += 1;

      if (!this._checkPrivate1(_precOp_1_0)) {
        return false;
      }
    }

    List<OperatorIDTuple> _succedingOperators_1_0 = _op.getSucceedingOperators();

    this._dim_0 = -1;
    this.o2 = new lupos.engine.operators.BasicOperator[_succedingOperators_1_0.size()];

    for (OperatorIDTuple _sucOpIDTup_1_0 : _succedingOperators_1_0) {
      this._dim_0 += 1;

      if (!this._checkPrivate2(_sucOpIDTup_1_0.getOperator())) {
        return false;
      }
    }

    return true;
  }
 public void logDeletedOperatorsBelow(
     final BasicOperator parent, final Collection<BasicOperator> deleted) {
   if (parent.getPrecedingOperators().size() < 2) {
     deleted.add(parent);
     final OperatorIDTuple[] opIDTuples =
         parent.getSucceedingOperators().toArray(new OperatorIDTuple[0]);
     for (final OperatorIDTuple opIDTuple : opIDTuples) {
       logDeletedOperatorsBelow(opIDTuple.getOperator(), deleted);
     }
   }
 }
 public void deleteAllBelow(
     final BasicOperator parent,
     final BasicOperator child,
     final Collection<BasicOperator> deleted) {
   if (child.getPrecedingOperators().size() > 1) {
     parent.removeSucceedingOperator(child);
     child.removePrecedingOperator(parent);
   } else {
     deleted.add(parent);
     final OperatorIDTuple[] opIDTuples =
         child.getSucceedingOperators().toArray(new OperatorIDTuple[0]);
     for (final OperatorIDTuple opIDTuple : opIDTuples) {
       deleteAllBelow(child, opIDTuple.getOperator(), deleted);
     }
   }
 }
  @Override
  protected Tuple<Collection<BasicOperator>, Collection<BasicOperator>> transformOperatorGraph(
      final Map<String, BasicOperator> mso, final BasicOperator rootOperator) {
    final Collection<BasicOperator> deleted = new LinkedList<BasicOperator>();
    final Collection<BasicOperator> added = new LinkedList<BasicOperator>();
    final Filter filter = (Filter) mso.get("filter");

    for (final BasicOperator parent : filter.getPrecedingOperators())
      deleteAllAbove(filter, parent, deleted);
    final OperatorIDTuple[] opIDTuples =
        filter.getSucceedingOperators().toArray(new OperatorIDTuple[0]);
    for (final OperatorIDTuple opIDTuple : opIDTuples)
      deleteAllBelow(filter, opIDTuple.getOperator(), deleted);
    if (deleted.size() > 0 || added.size() > 0)
      return new Tuple<Collection<BasicOperator>, Collection<BasicOperator>>(added, deleted);
    else return null;
  }
  /** {@inheritDoc} */
  @Override
  public Tuple<Collection<BasicOperator>, Collection<BasicOperator>> transformOperatorGraph(
      final Map<String, BasicOperator> mso, final BasicOperator rootOperator) {
    final Collection<BasicOperator> deleted = new LinkedList<BasicOperator>();
    final Collection<BasicOperator> added = new LinkedList<BasicOperator>();
    final ReplaceVar replaceVar = (ReplaceVar) mso.get("replaceVar");

    final LinkedList<BasicOperator> pres =
        (LinkedList<BasicOperator>) replaceVar.getPrecedingOperators();
    final LinkedList<OperatorIDTuple> succs =
        (LinkedList<OperatorIDTuple>) replaceVar.getSucceedingOperators();

    BasicOperator pre;
    OperatorIDTuple idTuple;
    // Connect all precessors to all successors
    for (int i = 0; i < pres.size(); i++) {
      for (int a = 0; a < succs.size(); a++) {
        idTuple = succs.get(a);
        pre = pres.get(i);
        pre.addSucceedingOperator(new OperatorIDTuple(idTuple.getOperator(), idTuple.getId()));
        pre.removeSucceedingOperator(replaceVar);
      }
    }

    BasicOperator succ;
    // And all successors to all precessors
    for (int i = 0; i < succs.size(); i++) {
      for (int a = 0; a < pres.size(); a++) {
        succ = succs.get(i).getOperator();
        succ.addPrecedingOperator(pres.get(a));
        succ.removePrecedingOperator(replaceVar);
      }
    }

    rootOperator.deleteParents();
    rootOperator.setParents();
    rootOperator.detectCycles();
    // should have been done manually: rootOperator.sendMessage(new
    // BoundVariablesMessage());
    deleted.add(replaceVar);
    if (deleted.size() > 0 || added.size() > 0)
      return new Tuple<Collection<BasicOperator>, Collection<BasicOperator>>(added, deleted);
    else return null;
  }
  private boolean _checkPrivate0(BasicOperator _op) {
    if (_op.getClass() != lupos.rif.operator.PredicatePattern.class) {
      return false;
    }

    this.p = (lupos.rif.operator.PredicatePattern) _op;

    List<BasicOperator> _precedingOperators_1_0 = _op.getPrecedingOperators();

    this._dim_0 = -1;
    this.o1 = new lupos.engine.operators.BasicOperator[_precedingOperators_1_0.size()];

    for (BasicOperator _precOp_1_0 : _precedingOperators_1_0) {
      this._dim_0 += 1;

      if (!this._checkPrivate1(_precOp_1_0)) {
        return false;
      }
    }

    List<OperatorIDTuple> _succedingOperators_1_0 = _op.getSucceedingOperators();

    if (_succedingOperators_1_0.size() != 1) {
      return false;
    }

    for (OperatorIDTuple _sucOpIDTup_1_0 : _succedingOperators_1_0) {
      if (!(_sucOpIDTup_1_0.getOperator() instanceof lupos.engine.operators.BasicOperator)) {
        continue;
      }

      this.o2 = (lupos.engine.operators.BasicOperator) _sucOpIDTup_1_0.getOperator();

      return true;
    }

    return false;
  }
  public void deleteAllAbove(
      final BasicOperator parent,
      final BasicOperator child,
      final Collection<BasicOperator> deleted) {
    parent.removeSucceedingOperator(child);
    if (!(parent instanceof PatternMatcher)) {

      // log parent as deleted operator
      deleted.add(parent);

      // in addition, log all operators (other than child) below parent, that became unrechable
      if (parent.getSucceedingOperators().size() > 0) {
        final OperatorIDTuple[] opIDTuples =
            parent.getSucceedingOperators().toArray(new OperatorIDTuple[0]);
        for (final OperatorIDTuple opIDTuple : opIDTuples) {
          logDeletedOperatorsBelow(opIDTuple.getOperator(), deleted);
        }
      }

      for (final BasicOperator parentparent : parent.getPrecedingOperators()) {
        deleteAllAbove(parentparent, parent, deleted);
      }
    }
  }