MaxFunction implements DDMExpressionFunction.Function1<Object[], BigDecimal> { @Override public BigDecimal apply(Object[] values) { return Stream.of( values ).map( value -> new BigDecimal(value.toString()) ).collect( Collectors.maxBy((num1, num2) -> num1.compareTo(num2)) ).orElse( BigDecimal.ZERO ); }  @Override BigDecimal apply(Object[] values); @Override String getName(); static final String NAME; }
@Test public void testEmptyArray() { MaxFunction maxFunction = new MaxFunction(); BigDecimal result = maxFunction.apply(new BigDecimal[0]); Assert.assertEquals(BigDecimal.ZERO, result); }
@Test public void testMax() { MaxFunction maxFunction = new MaxFunction(); BigDecimal result = maxFunction.apply( new BigDecimal[] { new BigDecimal(1), new BigDecimal(10), new BigDecimal(3), new BigDecimal(19), new BigDecimal(17) }); Assert.assertEquals(new BigDecimal(19), result); }