SumFunction implements DDMExpressionFunction.Function1<Object[], BigDecimal> { @Override public BigDecimal apply(Object[] values) { return Stream.of( values ).map( value -> new BigDecimal(value.toString()) ).collect( Collectors.reducing(BigDecimal.ZERO, (num1, num2) -> num1.add(num2)) ); }  @Override BigDecimal apply(Object[] values); @Override String getName(); static final String NAME; }
@Test public void testApply() { SumFunction sumFunction = new SumFunction(); BigDecimal result = sumFunction.apply( new BigDecimal[] { new BigDecimal(1), new BigDecimal(2), new BigDecimal(3) }); Assert.assertEquals(new BigDecimal(6), result); }
@Test public void testEmptyArray() { SumFunction sumFunction = new SumFunction(); BigDecimal result = sumFunction.apply(new BigDecimal[0]); Assert.assertEquals(BigDecimal.ZERO, result); }