/** * Create a Function that returns the given values based on whether the specified criterion passes */ public static <T> Function<T> caseWhen(final Criterion when, final Object ifTrue, final Object ifFalse) { return caseWhen(when, ifTrue).elseExpr(ifFalse).end(); }
/** * Sort the results by the value of the {@link Field}, ordered by values in the array. This is a bit of a hack. * * @param field the Field to order by * @param order values for the specified field, in the order they should appear in the result set */ public static <T> Order byArray(Field<T> field, T[] order) { if (order == null || order.length == 0) { return Order.asc("0"); } CaseBuilder caseBuilder = Function.caseExpr(field); for (int i = 0; i < order.length; i++) { caseBuilder.when(order[i], i); } caseBuilder.elseExpr(order.length); return Order.asc(caseBuilder.end()); }
/** * Create a Function that returns the given values based on whether the specified criterion passes */ public static <T> Function<T> caseWhen(final Criterion when, final Object ifTrue, final Object ifFalse) { return caseWhen(when, ifTrue).elseExpr(ifFalse).end(); }
.when("b", FAIL) .when("c", FAIL) .elseExpr(PASS) .end(); Property<?> test = StringProperty.fromFunction(caseWhen, "test"); .when(null, FAIL) .when(Field.NULL, FAIL) .elseExpr(PASS) .end(); test = StringProperty.fromFunction(caseWhen, "test"); .elseExpr(FAIL) .end(); test = StringProperty.fromFunction(caseWhen, "test"); .elseExpr("zero") .end(); test = StringProperty.fromFunction(caseWhen, "test"); .when(0, "zero") .when(7, "default") .elseExpr("other") .end(); test = StringProperty.fromFunction(caseWhen, "test");
/** * Sort the results by the value of the {@link Field}, ordered by values in the array. This is a bit of a hack. * * @param field the Field to order by * @param order values for the specified field, in the order they should appear in the result set */ public static <T> Order byArray(Field<T> field, T[] order) { if (order == null || order.length == 0) { return Order.asc("0"); } CaseBuilder caseBuilder = Function.caseExpr(field); for (int i = 0; i < order.length; i++) { caseBuilder.when(order[i], i); } caseBuilder.elseExpr(order.length); return Order.asc(caseBuilder.end()); }