Beispiel #1
0
  /**
   * Casts the specified value to Double data type.
   *
   * @see DataType#DOUBLE
   */
  private static Double toDouble(Object value) {

    if (value instanceof Double) {
      return (Double) value;
    } else if ((value instanceof Float) || (value instanceof Integer)) {
      Number number = (Number) value;

      return Double.valueOf(number.doubleValue());
    }

    throw new TypeCheckException(DataType.DOUBLE, value);
  }
Beispiel #2
0
  private static Number cast(DataType dataType, Number number) {

    switch (dataType) {
      case INTEGER:
        if (number instanceof Integer) {
          return number;
        }
        return Integer.valueOf(number.intValue());
      case FLOAT:
        if (number instanceof Float) {
          return number;
        }
        return Float.valueOf(number.floatValue());
      case DOUBLE:
        if (number instanceof Double) {
          return number;
        }
        return Double.valueOf(number.doubleValue());
      default:
        break;
    }

    throw new EvaluationException();
  }