Commit 8dfabbe3 authored by iwakeh's avatar iwakeh Committed by Karsten Loesing
Browse files

Return results in deterministic order.

Part of task-25002.
parent a9a0f705
......@@ -3,6 +3,11 @@
* Medium changes
- Stop omitting "n" in summary docs for "Unnamed" relays/bridges.
* Minor changes
- Make responses deterministic by always sorting results by
fingerprint, either if no specific order was requested or to
break ties after ordering results as requested.
# Changes in version 5.0-1.10.1 - 2018-02-07
......
......@@ -603,12 +603,10 @@ public class RequestHandler {
uniqueBridges.add(bridge);
}
}
if (this.order != null) {
Comparator<SummaryDocument> comparator
= new SummaryDocumentComparator(this.order);
Collections.sort(uniqueRelays, comparator);
Collections.sort(uniqueBridges, comparator);
}
Comparator<SummaryDocument> comparator
= new SummaryDocumentComparator(this.order);
Collections.sort(uniqueRelays, comparator);
Collections.sort(uniqueBridges, comparator);
this.orderedRelays.addAll(uniqueRelays);
this.orderedBridges.addAll(uniqueBridges);
}
......
......@@ -13,7 +13,8 @@ public class SummaryDocumentComparator implements Comparator<SummaryDocument> {
/** Comparator is initialized with the order parameters. */
public SummaryDocumentComparator(String ... orderParameters) {
this.orderParameters = orderParameters;
this.orderParameters
= null == orderParameters ? new String[]{} : orderParameters;
}
@Override
......@@ -45,6 +46,9 @@ public class SummaryDocumentComparator implements Comparator<SummaryDocument> {
break;
}
}
if (0 == result) {
result = o1.getFingerprint().compareTo(o2.getFingerprint());
}
return result;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment