@Override
 TemplateModel _eval(Environment env) throws TemplateException {
   TemplateNumberModel targetModel = null;
   TemplateModel tm = target.eval(env);
   try {
     targetModel = (TemplateNumberModel) tm;
   } catch (ClassCastException cce) {
     throw new NonNumericalException(target, tm, env);
   }
   if (!isMinus) {
     return targetModel;
   }
   target.assertNonNull(targetModel, env);
   Number n = targetModel.getAsNumber();
   n = ArithmeticEngine.CONSERVATIVE_ENGINE.multiply(MINUS_ONE, n);
   return new SimpleNumber(n);
 }
Esempio n. 2
0
 static Number getNumber(TemplateNumberModel model, Expression expr, Environment env)
     throws TemplateModelException, TemplateException {
   Number value = model.getAsNumber();
   if (value == null) {
     throw new TemplateException(expr + " evaluated to null number.", env);
   }
   return value;
 }
Esempio n. 3
0
  /**
   * Override the <code>Object.equals</code> method.
   *
   * @param o the object we're comparing against
   * @return <code>true</code> if the two objects are equal, otherwise <code>false</code>
   */
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (!(o instanceof NumberLiteral)) {
      return false;
    }

    final NumberLiteral numberLiteral = (NumberLiteral) o;

    if (value == null) {
      return numberLiteral.value == null;
    } else {
      return value.equals(numberLiteral.value);
    }
  }
Esempio n. 4
0
 /**
  * Override the <code>Object.hashCode</code> method.
  *
  * @return a hash code corresponding to the value of this object
  */
 public int hashCode() {
   return value.hashCode() + 17;
 }
Esempio n. 5
0
 /**
  * Override the <code>Object.toString</code> method.
  *
  * @return a <code>String</code> representation of this expression
  */
 public String toString() {
   return value.toString();
 }