@@ -623,11 +623,13 @@ public static FuncTaskConfigurer switchCase(String taskName, SwitchCaseConfigure
623623 *
624624 * @param pred predicate
625625 * @param thenTask task name when predicate is true
626+ * @param predClass predicate class
626627 * @param <T> predicate input type
627628 * @return list configurer
628629 */
629- public static <T > FuncTaskConfigurer switchWhen (Predicate <T > pred , String thenTask ) {
630- return list -> list .switchCase (cases (caseOf (pred ).then (thenTask )));
630+ public static <T > FuncTaskConfigurer switchWhen (
631+ Predicate <T > pred , String thenTask , Class <T > predClass ) {
632+ return list -> list .switchCase (cases (caseOf (pred , predClass ).then (thenTask )));
631633 }
632634
633635 public static FuncTaskConfigurer switchWhen (String jqExpression , String thenTask ) {
@@ -640,13 +642,15 @@ public static FuncTaskConfigurer switchWhen(String jqExpression, String thenTask
640642 * @param pred predicate
641643 * @param thenTask task name when predicate is true
642644 * @param otherwise default flow directive when predicate is false
645+ * @param predClass predicate class
643646 * @param <T> predicate input type
644647 * @return list configurer
645648 */
646649 public static <T > FuncTaskConfigurer switchWhenOrElse (
647- Predicate <T > pred , String thenTask , FlowDirectiveEnum otherwise ) {
650+ Predicate <T > pred , String thenTask , FlowDirectiveEnum otherwise , Class < T > predClass ) {
648651 return list ->
649- list .switchCase (FuncDSL .cases (caseOf (pred ).then (thenTask ), caseDefault (otherwise )));
652+ list .switchCase (
653+ FuncDSL .cases (caseOf (pred , predClass ).then (thenTask ), caseDefault (otherwise )));
650654 }
651655
652656 /**
@@ -655,12 +659,14 @@ public static <T> FuncTaskConfigurer switchWhenOrElse(
655659 * @param pred predicate
656660 * @param thenTask task name when predicate is true
657661 * @param otherwiseTask task name when predicate is false
662+ * @param predClass predicate class
658663 * @param <T> predicate input type
659664 * @return list configurer
660665 */
661666 public static <T > FuncTaskConfigurer switchWhenOrElse (
662- Predicate <T > pred , String thenTask , String otherwiseTask ) {
663- return list -> list .switchCase (cases (caseOf (pred ).then (thenTask ), caseDefault (otherwiseTask )));
667+ Predicate <T > pred , String thenTask , String otherwiseTask , Class <T > predClass ) {
668+ return list ->
669+ list .switchCase (cases (caseOf (pred , predClass ).then (thenTask ), caseDefault (otherwiseTask )));
664670 }
665671
666672 /**
@@ -765,35 +771,4 @@ public static FuncTaskConfigurer set(String expr) {
765771 public static FuncTaskConfigurer set (Map <String , Object > map ) {
766772 return list -> list .set (s -> s .expr (map ));
767773 }
768-
769- // ----- JQ helpers for outputAs / inputFrom ----- //
770-
771- /**
772- * JQ: pick the first element if the value is an array, otherwise return the value as-is. Does not
773- * stringify. Useful when downstream expects non-string JSON.
774- *
775- * <pre>(first(.[]? // empty) // .)</pre>
776- */
777- public static String selectFirst () {
778- return "(first(.[]? // empty) // .)" ;
779- }
780-
781- /**
782- * JQ: stringify the value only if it is not already a string.
783- *
784- * <pre>(if type==\"string\" then . else tostring end)</pre>
785- */
786- public static String stringifyIfNeeded () {
787- return "(if type==\" string\" then . else tostring end)" ;
788- }
789-
790- /**
791- * JQ: common “normalize to string”: - if array -> take first element - if null/empty -> coerce to
792- * empty string - if not a string -> tostring
793- *
794- * <pre>(first(.[]? // empty) // . // \"\") | (if type==\"string\" then . else tostring end)</pre>
795- */
796- public static String selectFirstStringify () {
797- return "(first(.[]? // empty) // . // \" \" ) | (if type==\" string\" then . else tostring end)" ;
798- }
799774}
0 commit comments