Exemple #1
0
    @Override
    public FieldValue evaluate(List<FieldValue> values) {

      if (values.size() != 2) {
        throw new EvaluationException();
      }

      FieldValue left = values.get(0);
      FieldValue right = values.get(1);

      // "If one of the input fields of a simple arithmetic function is a missing value, the result
      // evaluates to missing value"
      if (left == null || right == null) {
        return null;
      }

      DataType dataType = TypeUtil.getResultDataType(left.getDataType(), right.getDataType());

      Number result;

      try {
        result = evaluate(left.asNumber(), right.asNumber());
      } catch (ArithmeticException ae) {
        throw new InvalidResultException(null);
      }

      return FieldValueUtil.create(cast(dataType, result));
    }
Exemple #2
0
 private static void checkVariableArguments(
     List<FieldValue> values, int size, boolean allowNulls) {
   boolean success = (values.size() >= size) && (allowNulls ? true : !values.contains(null));
   if (!success) {
     throw new EvaluationException();
   }
 }
Exemple #3
0
    @Override
    public FieldValue evaluate(List<FieldValue> values) {
      checkVariableArguments(values, 2);

      Boolean result = evaluate(values.get(0), values.subList(1, values.size()));

      return FieldValueUtil.create(result);
    }
Exemple #4
0
    @Override
    public FieldValue evaluate(List<FieldValue> values) {
      checkArguments(values, 2);

      FieldValue left = values.get(0);
      FieldValue right = values.get(1);

      Boolean result = evaluate((left).compareToValue(right));

      return FieldValueUtil.create(result);
    }
Exemple #5
0
    @Override
    public FieldValue evaluate(List<FieldValue> values) {
      checkVariableArguments(values, 2);

      Boolean result = (values.get(0)).asBoolean();

      for (int i = 1; i < values.size(); i++) {
        result = evaluate(result, (values.get(i)).asBoolean());
      }

      return FieldValueUtil.create(result);
    }
  public void addEvent(LocalDate dt, Event e) {
    Years yr = Years.years(dt.getYear());
    Map<LocalDate, List<Event>> currEventMap = eventsMap.get(yr);
    if (currEventMap == null) {
      currEventMap = new TreeMap<LocalDate, List<Event>>();
    }

    List<Event> eventList = currEventMap.get(dt);
    if (eventList == null) {
      eventList = new ArrayList<Event>();
    }
    eventList.add(e);
    currEventMap.put(dt, eventList);
    eventsMap.put(yr, currEventMap);
  }
Exemple #7
0
  public static FieldValue evaluate(
      DefineFunction defineFunction, List<FieldValue> values, EvaluationContext context) {
    List<ParameterField> parameterFields = defineFunction.getParameterFields();

    if (parameterFields.size() < 1) {
      throw new InvalidFeatureException(defineFunction);
    } // End if

    if (parameterFields.size() != values.size()) {
      throw new EvaluationException();
    }

    FunctionEvaluationContext functionContext = new FunctionEvaluationContext(context);

    for (int i = 0; i < parameterFields.size(); i++) {
      ParameterField parameterField = parameterFields.get(i);

      FieldValue value = FieldValueUtil.refine(parameterField, values.get(i));

      functionContext.declare(parameterField.getName(), value);
    }

    Expression expression = defineFunction.getExpression();
    if (expression == null) {
      throw new InvalidFeatureException(defineFunction);
    }

    FieldValue result = ExpressionUtil.evaluate(expression, functionContext);

    return FieldValueUtil.refine(defineFunction.getDataType(), defineFunction.getOptype(), result);
  }
Exemple #8
0
    @Override
    public FieldValue evaluate(List<FieldValue> values) {
      checkArguments(values, 1);

      FieldValue value = values.get(0);

      String result = evaluate(value.asString());

      return FieldValueUtil.create(result);
    }
Exemple #9
0
    @Override
    public FieldValue evaluate(List<FieldValue> values) {
      checkArguments(values, 1, true);

      FieldValue value = values.get(0);

      Boolean result = evaluate(value);

      return FieldValueUtil.create(result);
    }
Exemple #10
0
    @Override
    public FieldValue evaluate(List<FieldValue> values) {
      checkArguments(values, 1);

      FieldValue value = values.get(0);

      Number result = cast(getResultType(value.getDataType()), evaluate(value.asNumber()));

      return FieldValueUtil.create(result);
    }
Exemple #11
0
 protected void addLocation(Location location) {
   locations.add(location);
 }
 protected void setUp() {
   addressBookList.add(book1);
   addressBookList.add(book2);
   addressBookList.add(book3);
   addressBookList.add(book4);
 }