/** * Implements a negated exists. * <p> * Returns <strong>false</strong> when at least one of the elements of the list * <strong>matches</strong> the target. * The list may contain both objects (equals) and UnaryTests (apply) */ public static Boolean notExists( EvaluationContext ctx, List tests, Object target) { for (Object test : tests) { Boolean r = applyUnaryTest(ctx, test, target); if (r == null || r) { return false; } } return true; }
public static Object negateTest(Object param) { if (param instanceof Boolean) { return param.equals(Boolean.FALSE); } else if (param instanceof UnaryTest) { UnaryTest orig = (UnaryTest) param; UnaryTest t = negatedUnaryTest(orig); return t; } else if (param instanceof Range) { UnaryTest t = (c, left) -> not(includes(c, param, left)); return t; } else { UnaryTest t = (c, left) -> not(eq(left, param)); return t; } }
/** * Represents a [n..m] construct */ public static RangeImpl range( EvaluationContext ctx, Range.RangeBoundary lowBoundary, Object lowEndPoint, Object highEndPoint, Range.RangeBoundary highBoundary) { Comparable left = asComparable(lowEndPoint); Comparable right = asComparable(highEndPoint); if (left == null || right == null || !compatible(left, right)) { ctx.notifyEvt(() -> new ASTEventBase( FEELEvent.Severity.ERROR, Msg.createMessage( Msg.INCOMPATIBLE_TYPE_FOR_RANGE, left.getClass().getSimpleName() ), null)); return null; } return new RangeImpl( lowBoundary, left, right, highBoundary); }
public static Boolean between(EvaluationContext ctx, Object value, Object start, Object end) { if (value == null) { ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.IS_NULL, "value"), null)); return null; } if (start == null) { ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.IS_NULL, "start"), null)); return null; } if (end == null) { ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.IS_NULL, "end"), null)); return null; } if (!value.getClass().isAssignableFrom(start.getClass())) { ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.X_TYPE_INCOMPATIBLE_WITH_Y_TYPE, "value", "start"), null)); return null; } if (!value.getClass().isAssignableFrom(end.getClass())) { ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.X_TYPE_INCOMPATIBLE_WITH_Y_TYPE, "value", "end"), null)); return null; } return gte(value, start) && lte(value, end); }
public static Boolean gracefulEq(EvaluationContext ctx, Object left, Object right) { if (left instanceof List) { return ((List) left).contains(right); } else { return eq(left, right); } }
return null; } else { return list(range).contains(param);
/** 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)); }
/** * Returns true when at least one of the elements of the list matches the target. * The list may contain both objects (equals) and UnaryTests (apply) */ public static Boolean exists( EvaluationContext ctx, Object tests, Object target) { if (!(tests instanceof List)) { if (tests == null) { ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.IS_NULL, "value"), null)); return null; } return applyUnaryTest(ctx, tests, target); } for (Object test : (List) tests) { Boolean r = applyUnaryTest(ctx, test, target); if (Boolean.TRUE.equals(r)) { return true; } } return false; }