@@ -45,19 +45,35 @@ public static <T> Map<String, List<String>> filterMap(Map<String, T> map, List<S
4545 .filter (entry -> isMatch (entry .getValue (), searchValues , filterType ))
4646 .collect (Collectors .toMap (
4747 Map .Entry ::getKey ,
48- e -> e .getValue ().stream ()
49- // Standard alphabetical sort that accounts for symbols and numbers.
50- // But uppercase letters are positioned before lowercase letters.
51- .sorted (Comparator
52- .comparing ((String s ) -> s .substring (0 , 1 ).toLowerCase ())
53- .thenComparing (s -> s .substring (0 , 1 ))
54- .thenComparing (s -> s ))
55- .collect (Collectors .toList ()),
48+ e -> sortValues (e .getValue ()),
5649 (e1 , e2 ) -> e1 ,
5750 LinkedHashMap ::new
5851 ));
5952 }
6053
54+ /**
55+ * Standard alphabetical sort that accounts for symbols and numbers.
56+ * Uppercase letters are positioned before lowercase letters.
57+ */
58+ public static List <String > sortValues (List <String > values )
59+ {
60+ return values .stream ()
61+ .peek (s -> { if (s .isEmpty ()) throw new IllegalArgumentException ("Empty values aren't allowed: " + values );})
62+ .sorted (Comparator
63+ .comparing ((String s ) -> s .substring (0 , 1 ).toLowerCase ())
64+ .thenComparing (s -> s .substring (0 , 1 ))
65+ .thenComparing (s -> s ))
66+ .collect (Collectors .toList ());
67+ }
68+
69+ /**
70+ * Sorts values alphabetically and joins them with the given separator.
71+ */
72+ public static String sortAndJoin (List <String > values , String separator )
73+ {
74+ return String .join (separator , sortValues (values ));
75+ }
76+
6177 public static Map <String , String > prepareMapForCheck (Map <String , List <String >> map )
6278 {
6379 return map .entrySet ().stream ()
@@ -87,6 +103,11 @@ public static List<String> parseMultiValueText(String multiValueString) throws I
87103 }
88104 }
89105
106+ public static <T > String formatMultiValueText (List <T > values )
107+ {
108+ return values .stream ().map (CSVFormat .DEFAULT ::format ).collect (Collectors .joining ("," ));
109+ }
110+
90111 private static boolean isMatch (List <String > actualValues , List <String > searchValues , Filter .Operator type )
91112 {
92113 return switch (type )
0 commit comments