Exemplo n.º 1
0
  /**
   * Given the TupleExpr, replace the existence of a UnaryTupleOperator with the provided unary
   * operator. If there is nothing in the model that matches, the provided unary operator will be
   * placed at the root of the model.
   *
   * @param theExpr the expression
   * @param theNewProj the operator to replace the projectino with
   * @return the expression w/ the projection operator removed
   */
  public TupleExpr replace(final TupleExpr theExpr, final UnaryTupleOperator theNewProj) {
    Visitor aVisitor = new Visitor();

    try {
      theExpr.visit(aVisitor);
    } catch (Exception e) {
      // we really should not get an exception here
      throw new RuntimeException(e);
    }

    UnaryTupleOperator aProj = mOperator;

    if (aProj == null && insertIfNotPresent) {
      theNewProj.setArg(theExpr);

      return theNewProj;
    } else if (aProj != null && aProj.getParentNode() != null) {
      aProj.replaceWith(theNewProj);

      return theExpr;
    } else if (aProj != null) {
      theNewProj.setArg(aProj.getArg());
      return theNewProj;
    } else {
      return theExpr;
    }
  }
 public long getCardinality(UnaryTupleOperator op, BindingSet bindings) {
   return getCardinality(op.getArg(), bindings);
 }