Exemple #1
0
  public Expr evaluate(Expr[] args) throws ExprException {
    assertArgCount(args, 1);

    Expr a = evalArg(args[0]);
    String s = null;

    if (a instanceof ExprString) {
      s = ((ExprString) a).str;
    } else if (a instanceof ExprNumber) {
      s = a.toString();
    }

    if (s != null && s.length() > 0) return new ExprInteger(s.charAt(0));

    return ExprError.VALUE;
  }
Exemple #2
0
  private double findChange(Expr old, Expr nu) {
    if (old == null || nu == null) return 0;

    if (old.type != nu.type) return 0;

    if (nu instanceof ExprNumber) {
      return Math.abs(((ExprNumber) old).doubleValue() - ((ExprNumber) nu).doubleValue());
    }

    if (nu instanceof ExprArray) {
      Expr[] oldA = old.getArgs();
      Expr[] nuA = nu.getArgs();

      double change = 0;
      for (int i = 0; i < oldA.length && i < nuA.length; i++) {
        double c = findChange(oldA[i], nuA[i]);
        if (c > change) change = c;
      }

      return change;
    }

    return 0;
  }