ExpressionContext { public void registerFunc(String func, Method method) { context.addImport(func, method); } ExpressionContext(); void registerFunc(String func, Method method); void registerFunc(Class<?> clz);  }
@Test public void testRegisterFuncWithMethod() throws NoSuchMethodException { ExpressionContext expressionContext = new ExpressionContext(); Method[] methods = Math.class.getMethods(); Arrays.stream(methods).forEach(method -> { if (method.getName().equalsIgnoreCase("sqrt")) { expressionContext.registerFunc("sqrt", method); } }); Expression expression = new Expression(expressionContext); Number number = (Number) expression.eval("sqrt(16)"); assertThat(number, is(4.0)); }
@Test public void testRegisterFuncWithClazz() throws NoSuchMethodException { ExpressionContext expressionContext = new ExpressionContext(); expressionContext.registerFunc(Math.class); Expression expression = new Expression(expressionContext); Number number = (Number) expression.eval("sqrt(16)"); assertThat(number, is(4.0)); number = (Number) expression.eval("abs(-12)"); assertThat(number, is(12)); }