Merge branch '2.3.x' into 2.4.x

Closes gh-26275
This commit is contained in:
Stephane Nicoll
2021-04-28 14:12:35 +02:00
2 changed files with 76 additions and 21 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -160,29 +160,22 @@ class JsonConverter {
private static class ItemMetadataComparator implements Comparator<ItemMetadata> {
private static final Comparator<ItemMetadata> GROUP = Comparator.comparing(ItemMetadata::getName)
.thenComparing(ItemMetadata::getSourceType, Comparator.nullsFirst(Comparator.naturalOrder()));
private static final Comparator<ItemMetadata> ITEM = Comparator.comparing(ItemMetadataComparator::isDeprecated)
.thenComparing(ItemMetadata::getName)
.thenComparing(ItemMetadata::getSourceType, Comparator.nullsFirst(Comparator.naturalOrder()));
@Override
public int compare(ItemMetadata o1, ItemMetadata o2) {
if (o1.isOfItemType(ItemType.GROUP)) {
return compareGroup(o1, o2);
return GROUP.compare(o1, o2);
}
return compareProperty(o1, o2);
return ITEM.compare(o1, o2);
}
private int compareGroup(ItemMetadata o1, ItemMetadata o2) {
return o1.getName().compareTo(o2.getName());
}
private int compareProperty(ItemMetadata o1, ItemMetadata o2) {
if (isDeprecated(o1) && !isDeprecated(o2)) {
return 1;
}
if (isDeprecated(o2) && !isDeprecated(o1)) {
return -1;
}
return o1.getName().compareTo(o2.getName());
}
private boolean isDeprecated(ItemMetadata item) {
private static boolean isDeprecated(ItemMetadata item) {
return item.getDeprecation() != null;
}