@Override public Object getValue(String name) { return wrapped.getValue(name); }
@Override public Object getValue(String[] name) { return wrapped.getValue(name); }
/** FEEL: max( 1, 2, 3 ) */ @Override public Object apply(EvaluationContext feelExprCtx) { return CompiledFEELSupport.invoke(feelExprCtx, feelExprCtx.getValue("max"), Arrays.asList(K_1, K_2, K_3)); }
private Object invokeTheFunction(List<String> names, FEELFunction fn, EvaluationContext ctx, Object[] params) { if (names.size() == 1) { Object result = fn.invokeReflectively(ctx, params); return result; } else { try { Object newRoot = ctx.getValue(names.get(0)); ctx.enterFrame(); try { Map<String, Object> asMap = ((Map<String, Object>) newRoot); asMap.forEach(ctx::setValue); } catch (ClassCastException e) { ctx.setRootObject(newRoot); // gracefully handle the less common scenario. } return invokeTheFunction(names.subList(1, names.size()), fn, ctx, params); } finally { ctx.exitFrame(); } } }
/** FEEL: for x in [ 10, 20, 30 ], y in [ 1, 2, 3 ] return x * y */ @Override public Object apply(EvaluationContext feelExprCtx) { return CompiledFEELSupport.ffor(feelExprCtx) .with(c -> "x", c -> Arrays.asList(K_10, K_20, K_30)) .with(c -> "y", c -> Arrays.asList(K_1, K_2, K_3)) .rreturn(c -> ((BigDecimal) feelExprCtx.getValue("x")).multiply((BigDecimal) feelExprCtx.getValue("y"))); }
/** FEEL: substring( start position: 2, string: "FOOBAR" ) */ @Override public Object apply(EvaluationContext feelExprCtx) { return CompiledFEELSupport.invoke( feelExprCtx, feelExprCtx.getValue("substring"), Arrays.asList(new NamedParameter("start position", K_1), new NamedParameter("string", K_s))); }
if ( name instanceof NameRefNode ) { value = ctx.getValue( name.getText() ); } else if (name instanceof QualifiedNameNode) { QualifiedNameNode qn = (QualifiedNameNode) name; String[] qns = qn.getPartsAsStringArray(); value = ctx.getValue( qns ); } else if (name instanceof PathExpressionNode) { PathExpressionNode pathExpressionNode = (PathExpressionNode) name;
@Override public Object evaluate(EvaluationContext ctx) { String varName = EvalHelper.normalizeVariableName( getText() ); if( ! ctx.isDefined( varName ) ) { ctx.notifyEvt( astEvent( FEELEvent.Severity.ERROR, Msg.createMessage( Msg.UNKNOWN_VARIABLE_REFERENCE, getText()), null) ); return null; } return ctx.getValue( varName ); }
/** FEEL: some price in [ 80, 11, 110 ] satisfies price > 100 */ @Override public Object apply(EvaluationContext feelExprCtx) { return CompiledFEELSupport.quant(Quantifier.SOME, feelExprCtx) .with(c -> "price", c -> Arrays.asList(K_80, K_11, K_110)) .satisfies(c -> gt(feelExprCtx.getValue("price"), K_100)); }
@Override public Map apply(EvaluationContext feelExprCtx) { return CompiledFEELSupport.openContext(feelExprCtx) .setEntry("an applicant", CompiledFEELSupport.openContext(feelExprCtx) .setEntry("home address", CompiledFEELSupport.openContext(feelExprCtx) .setEntry("street name", "broadway st") .setEntry("city", "New York") .closeContext()) .closeContext()) .setEntry("street", ((java.util.Map) ((java.util.Map) feelExprCtx.getValue("an applicant")).get("home address")).get("street name")) .closeContext(); } }