Exemplo n.º 1
0
  public Object evaluate() throws EvaluationException {
    try {
      Number l = (Number) left().evaluate();
      Number r = (Number) right().evaluate();

      if (l instanceof Float || l instanceof Double || r instanceof Float || r instanceof Double) {
        String[] parameters = {
          Util.getMessage("EvaluationException.and"),
          left().value().getClass().getName(),
          right().value().getClass().getName()
        };
        throw new EvaluationException(Util.getMessage("EvaluationException.1", parameters));
      } else {
        // Arithmetic and (&)
        // daz        value (new Long (l.longValue () & r.longValue ()));
        BigInteger uL = (BigInteger) coerceToTarget((BigInteger) l);
        BigInteger uR = (BigInteger) coerceToTarget((BigInteger) r);
        value(uL.and(uR));
      }
    } catch (ClassCastException e) {
      String[] parameters = {
        Util.getMessage("EvaluationException.and"),
        left().value().getClass().getName(),
        right().value().getClass().getName()
      };
      throw new EvaluationException(Util.getMessage("EvaluationException.1", parameters));
    }
    return value();
  } // evaluate
Exemplo n.º 2
0
  public Object evaluate() throws EvaluationException {
    try {
      Number l = (Number) left().evaluate();
      Number r = (Number) right().evaluate();

      boolean lIsNonInteger = l instanceof Float || l instanceof Double;
      boolean rIsNonInteger = r instanceof Float || r instanceof Double;

      if (lIsNonInteger && rIsNonInteger) value(new Double(l.doubleValue() + r.doubleValue()));
      else if (lIsNonInteger || rIsNonInteger) {
        String[] parameters = {
          Util.getMessage("EvaluationException.plus"),
          left().value().getClass().getName(),
          right().value().getClass().getName()
        };
        throw new EvaluationException(Util.getMessage("EvaluationException.1", parameters));
      } else {
        // Addition (+)
        BigInteger tmpL = (BigInteger) l, tmpR = (BigInteger) r;
        value(tmpL.add(tmpR));
        // daz        value (new Long (l.longValue () + r.longValue ()));
      }
    } catch (ClassCastException e) {
      String[] parameters = {
        Util.getMessage("EvaluationException.plus"),
        left().value().getClass().getName(),
        right().value().getClass().getName()
      };
      throw new EvaluationException(Util.getMessage("EvaluationException.1", parameters));
    }
    return value();
  } // evaluate