Exemplo n.º 1
0
  public Exp replace(Exp old, Exp replacement) {
    if (!(old instanceof QuantExp)) {
      if (where != null) {
        Exp whr = where.replace(old, replacement);
        if (whr != null) this.setWhere(whr);
      }
      if (body != null) {
        Exp bdy = body.replace(old, replacement);
        if (bdy != null) this.setBody(bdy);
        // Not used anywhere below. - YS
        // String str = bdy.toString(0, 0);
      }
      if (vars != null && old instanceof VarExp && replacement instanceof VarExp) {
        // What if Replacement isn't VarExp?
        List<MathVarDec> newVars = new List<MathVarDec>();
        Iterator<MathVarDec> i = vars.iterator();
        while (i.hasNext()) {
          MathVarDec tmp = i.next();
          if (tmp.getName().toString().equals(((VarExp) old).getName().toString())) {
            tmp.setName(((VarExp) replacement).getName());
          }

          newVars.add(tmp);
        }
      }
      return this;
    } else return this;
  }
Exemplo n.º 2
0
  public Exp replace(Exp old, Exp replacement) {
    if (old instanceof DotExp) {
      if (old.equals(this)) {
        return replacement;
      }
    }

    if ((old instanceof VarExp || old instanceof OldExp)) {
      Iterator<VariableExp> it = segments.iterator();

      if (it.hasNext()) {
        Exp name = it.next();
        if (old instanceof VarExp && name instanceof VarExp) {
          if (((VarExp) old).getName().toString().equals(((VarExp) name).getName().toString())) {
            segments.remove(0);
            segments.add(0, (VariableExp) (replacement.clone()));

            return this;
          }
        } else if (old instanceof OldExp && name instanceof OldExp) {
          name = name.replace(old, replacement);
          if (name != null) {
            segments.remove(0);
            segments.add(0, (VariableExp) (name.clone()));
            return this;
          }
        }
      }

      if (it.hasNext()) {
        Exp name = it.next();
        name = name.replace(old, replacement);
        if (name != null && name instanceof VariableExp) {
          segments.remove(1);

          segments.add(1, (VariableExp) (name.clone()));
          return this;
        }
      }
    }

    return this;
  }
Exemplo n.º 3
0
 public Exp replace(Exp olde, Exp newe) {
   // System.out.println("Exps: "+exps);
   if (equals(olde)) return newe;
   Exp e;
   for (int i = 0; i < exps.size(); i++) {
     e = exps.get(i);
     if (e.equals(olde)) exps.set(i, newe);
     else exps.set(i, e.replace(olde, newe));
     e = exps.get(i);
     if (e == null) return null;
   }
   return this;
 }