Fixed #2188: Can add and remove more than 10 tags at once. (#5040)

* Fixed adding more than 10 tags at a time
This commit is contained in:
Parth Panchal 2022-07-09 15:31:53 +05:30 committed by GitHub
parent d799d792a2
commit 3a7de3c677
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -183,12 +183,46 @@ public final class JsonUtils {
// sort the operations by path // sort the operations by path
if (!otherOperations.isEmpty()) { if (!otherOperations.isEmpty()) {
otherOperations.sort(Comparator.comparing(jsonObject -> jsonObject.getString("path"))); ArrayList<String> paths = new ArrayList<>();
for (JsonObject jsonObject : otherOperations) {
paths.add(jsonObject.getString("path"));
}
for (String path : paths) {
if (path.matches("^[a-zA-Z]*$")) {
otherOperations.sort(Comparator.comparing(jsonObject -> jsonObject.getString("path")));
} else if (path.matches(".*\\d.*")) {
otherOperations.sort(
Comparator.comparing(
jsonObject -> {
String pathValue = jsonObject.getString("path");
String tagIndex = pathValue.replaceAll("\\D", "");
return tagIndex.isEmpty() ? 0 : Integer.parseInt(tagIndex);
}));
}
}
} }
if (!removeOperations.isEmpty()) { if (!removeOperations.isEmpty()) {
removeOperations.sort(Comparator.comparing(jsonObject -> jsonObject.getString("path"))); ArrayList<String> paths = new ArrayList<>();
// reverse sort only the remove operations for (JsonObject jsonObject : removeOperations) {
Collections.reverse(removeOperations); paths.add(jsonObject.getString("path"));
}
for (String path : paths) {
if (path.matches("^[a-zA-Z]*$")) {
removeOperations.sort(Comparator.comparing(jsonObject -> jsonObject.getString("path")));
// reverse sort only the remove operations
Collections.reverse(removeOperations);
} else if (path.matches(".*\\d.*")) {
removeOperations.sort(
Comparator.comparing(
jsonObject -> {
String pathValue = jsonObject.getString("path");
String tagIndex = pathValue.replaceAll("\\D", "");
return tagIndex.isEmpty() ? 0 : Integer.parseInt(tagIndex);
}));
// reverse sort only the remove operations
Collections.reverse(removeOperations);
}
}
} }
// Build new sorted patch // Build new sorted patch