Skip to content

Commit

Permalink
Make comparator handle null as a possible argument
Browse files Browse the repository at this point in the history
  • Loading branch information
dnestoro committed Jun 3, 2024
1 parent 97c56cd commit 309f9da
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ private BundleConfiguration(BundleConfiguration other) {
}

public record ResourceEntry(String pattern, String module) {
public static Comparator<ResourceEntry> comparator() {
Comparator<ResourceEntry> moduleComparator = Comparator.comparing(ResourceEntry::module, Comparator.nullsFirst(Comparator.naturalOrder()));
Comparator<ResourceEntry> patternComparator = Comparator.comparing(ResourceEntry::pattern, Comparator.nullsFirst(Comparator.naturalOrder()));
return moduleComparator.thenComparing(patternComparator);
}
}

private final Set<ConditionalElement<String>> addedResources = Collections.newSetFromMap(new ConcurrentHashMap<>());
Expand Down Expand Up @@ -322,8 +327,7 @@ public void printJson(JsonWriter writer) throws IOException {
writer.unindent();
writer.append('}').append(',').newline();
writer.quote("globs").append(':');
JsonPrinter.printCollection(writer, addedGlobs, ConditionalElement.comparator(Comparator.comparing(ResourceEntry::pattern).thenComparing(ResourceEntry::module)),
ResourceConfiguration::conditionalGlobElementJson);
JsonPrinter.printCollection(writer, addedGlobs, ConditionalElement.comparator(ResourceEntry.comparator()), ResourceConfiguration::conditionalGlobElementJson);
writer.append(',').newline();
writer.quote("bundles").append(':');
JsonPrinter.printCollection(writer, bundles.keySet(), ConditionalElement.comparator(), (p, w) -> printResourceBundle(bundles.get(p), w));
Expand Down

0 comments on commit 309f9da

Please sign in to comment.