Пример #1
0
 public CompositeEvidence createEvidence(EvaluationExpression expr) {
   if (expr instanceof ArithmeticExpression) {
     CompositeEvidence evidence;
     ArithmeticExpression arithmeticExpr = (ArithmeticExpression) expr;
     ObjectCreation objectCreation;
     EvaluationExpression evaluationExpression;
     if (arithmeticExpr.getFirstOperand() instanceof ObjectCreation) {
       objectCreation = (ObjectCreation) arithmeticExpr.getFirstOperand();
       evaluationExpression = arithmeticExpr.getSecondOperand();
     } else {
       objectCreation = (ObjectCreation) arithmeticExpr.getSecondOperand();
       evaluationExpression = arithmeticExpr.getFirstOperand();
     }
     DecimalNode baseEvidence =
         (DecimalNode) evaluationExpression.evaluate(NullNode.getInstance());
     evidence = new CompositeEvidence(baseEvidence);
     for (Mapping<?> mapping : objectCreation.getMappings()) {
       evidence.putEvidence(
           this.getFieldName(mapping), this.createEvidence(mapping.getExpression()));
     }
     return evidence;
   }
   return new CompositeEvidence((DecimalNode) expr.evaluate(NullNode.getInstance()));
 }
    @Override
    protected void map(final IJsonNode value, JsonCollector<IJsonNode> out) {
      final IJsonNode target = this.arrayPath.evaluate(value);
      if (!(target instanceof IArrayNode<?>))
        throw new EvaluationException("Cannot split non-array");
      final IArrayNode<?> array = (IArrayNode<?>) target;

      int index = 0;
      IntNode indexNode = IntNode.valueOf(0);
      IArrayNode<IJsonNode> contextNode =
          JsonUtil.asArray(NullNode.getInstance(), indexNode, array, value);
      for (IJsonNode element : array) {
        contextNode.set(0, element);
        indexNode.setValue(index);
        out.collect(this.splitProjection.evaluate(contextNode));
        index++;
      }
    }
 @Test(expected = EvaluationException.class)
 public void shouldThrowException() {
   new UnevaluableExpression("TestExceptionMessage").evaluate(NullNode.getInstance());
 }
 @Override
 public boolean validate(IJsonNode value) {
   return value != NullNode.getInstance() && value != MissingNode.getInstance();
 }