Special handle lists with 2 or less elements.
@@ -47,6 +47,10 @@ public class Group extends Identifiable {
list.sort(cmp);
return list;
} else {
+ if (list.size() < 2) return list;
+ if (list.size() == 2) {
+ return (cmp.compare(list.get(0), list.get(1)) > 0) ? List.of(list.get(1), list.get(0)) : list;
+ }
return list.stream().sorted(cmp).collect(Collectors.toList());
}
}
