use of com.google.gerrit.server.util.MostSpecificComparator in project gerrit by GerritCodeReview.
the class SectionSortCache method sort.
void sort(String ref, List<AccessSection> sections) {
final int cnt = sections.size();
if (cnt <= 1) {
return;
}
EntryKey key = EntryKey.create(ref, sections);
EntryVal val = cache.getIfPresent(key);
if (val != null) {
int[] srcIdx = val.order;
if (srcIdx != null) {
AccessSection[] srcList = copy(sections);
for (int i = 0; i < cnt; i++) {
sections.set(i, srcList[srcIdx[i]]);
}
} else {
// Identity transform. No sorting is required.
}
} else {
boolean poison = false;
IdentityHashMap<AccessSection, Integer> srcMap = new IdentityHashMap<>();
for (int i = 0; i < cnt; i++) {
poison |= srcMap.put(sections.get(i), i) != null;
}
Collections.sort(sections, new MostSpecificComparator(ref));
int[] srcIdx;
if (isIdentityTransform(sections, srcMap)) {
srcIdx = null;
} else {
srcIdx = new int[cnt];
for (int i = 0; i < cnt; i++) {
srcIdx[i] = srcMap.get(sections.get(i));
}
}
if (poison) {
log.error("Received duplicate AccessSection instances, not caching sort");
} else {
cache.put(key, new EntryVal(srcIdx));
}
}
}
Aggregations