Skip to content

Commit

Permalink
Refactor implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenada committed Mar 21, 2024
1 parent b8b0733 commit 12bc753
Showing 1 changed file with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,22 +329,13 @@ public static List<RelCollation> sort(RelCollation collation) {
if (integers.isEmpty()) {
continue loop; // cannot do this collation
}
if (integers.size() == 1) {
for (List<RelFieldCollation> fieldCollations : fieldCollationsList) {
fieldCollations.add(ifc.withFieldIndex(integers.iterator().next()));
}
} else {
List<List<RelFieldCollation>> newFieldCollationsList =
new ArrayList<>(fieldCollationsList.size() * integers.size());
for (List<RelFieldCollation> fieldCollations : fieldCollationsList) {
for (Integer integer : integers) {
List<RelFieldCollation> newFieldCollations = new ArrayList<>(fieldCollations);
newFieldCollations.add(ifc.withFieldIndex(integer));
newFieldCollationsList.add(newFieldCollations);
}
}
fieldCollationsList = newFieldCollationsList;
}
fieldCollationsList = fieldCollationsList.stream()
.flatMap(fieldCollations -> integers.stream()
.map(integer -> {
List<RelFieldCollation> newFieldCollations = new ArrayList<>(fieldCollations);
newFieldCollations.add(ifc.withFieldIndex(integer));
return newFieldCollations;
})).collect(Collectors.toList());
}
assert !fieldCollationsList.isEmpty();
for (List<RelFieldCollation> fieldCollations : fieldCollationsList) {
Expand Down

0 comments on commit 12bc753

Please sign in to comment.