AllFunction implements DDMExpressionFunction.Function2<String, Object, Boolean> { @Override public Boolean apply(String expression, Object parameter) { if (!expression.contains("#value#")) { return false; } Object[] values = null; if (isArray(parameter)) { values = (Object[])parameter; if (values.length == 0) { return false; } } else { values = new Object[] {parameter}; } return Stream.of( values ).allMatch( value -> accept(expression, value) ); } AllFunction(DDMExpressionFactory ddmExpressionFactory); @Override Boolean apply(String expression, Object parameter); @Override String getName(); static final String NAME; }
@Test public void testArrayFalse() throws Exception { Boolean result = (Boolean)_allFunction.apply( "#value# >= 1", new BigDecimal[] { new BigDecimal(0), new BigDecimal(2), new BigDecimal(3) }); Assert.assertFalse(result); }
@Test public void testArrayTrue() throws Exception { Boolean result = (Boolean)_allFunction.apply( "#value# >= 1", new BigDecimal[] { new BigDecimal(1), new BigDecimal(2), new BigDecimal(3) }); Assert.assertTrue(result); }
@Test public void testEmptyArray() throws Exception { Boolean result = (Boolean)_allFunction.apply( "#value# >= 1", new BigDecimal[0]); Assert.assertFalse(result); }
@Test public void testInvalidExpression1() throws Exception { Boolean result = (Boolean)_allFunction.apply("#invalid# > 10", 11); Assert.assertFalse(result); }
@Test public void testInvalidExpression2() throws Exception { Boolean result = (Boolean)_allFunction.apply("#value# >>> 10", 11); Assert.assertFalse(result); }
@Test public void testSingleValue() throws Exception { Boolean result = (Boolean)_allFunction.apply("#value# >= 1", 2); Assert.assertTrue(result); }