[metrics-bugs] #24327 [Metrics/ExoneraTor]: Sort results under technical details by timestamp and, if necessary, by fingerprint

Tor Bug Tracker & Wiki blackhole at torproject.org
Mon Nov 20 15:29:54 UTC 2017


#24327: Sort results under technical details by timestamp and, if necessary, by
fingerprint
--------------------------------+--------------------------------
 Reporter:  karsten             |          Owner:  metrics-team
     Type:  defect              |         Status:  needs_revision
 Priority:  Medium              |      Milestone:
Component:  Metrics/ExoneraTor  |        Version:
 Severity:  Normal              |     Resolution:
 Keywords:                      |  Actual Points:
Parent ID:                      |         Points:
 Reviewer:                      |        Sponsor:
--------------------------------+--------------------------------
Changes (by iwakeh):

 * status:  needs_review => needs_revision


Comment:

 As the ordering is simply for sorting the matches for returning them, it
 should rather be given as special comparator argument to the
 Collections.sort method than defining it as the Comparator of the Match
 class.  Defining it as the Comparator with the Match class somewhat
 indicates that this is a natural ordering, which ought be consistent with
 equals, which is not the case and not intended here.  (Of course, from the
 data point of view there shouldn't be matches not differing in the two
 fields used for comparison and differing in other fields of the Match
 class, but that is not always guaranteed.)

 Better to limit the changes to the one place where the sorting is done:
 {{{
 --- a/src/main/java/org/torproject/exonerator/QueryServlet.java
 +++ b/src/main/java/org/torproject/exonerator/QueryServlet.java
 @@ -18,6 +18,7 @@ import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Calendar;
 +import java.util.Collections;
  import java.util.List;
  import java.util.SortedSet;
  import java.util.TimeZone;
 @@ -338,6 +339,15 @@ public class QueryServlet extends HttpServlet {
          }
        }
        if (!matches.isEmpty()) {
 +        Collections.sort(matches,
 +            (m1, m2) -> {
 +            if (m1 == m2) {
 +              return 0;
 +            } else if (!m1.timestamp.equals(m2.timestamp)) {
 +              return m1.timestamp.compareTo(m2.timestamp);
 +            } else {
 +              return m1.fingerprint.compareTo(m2.fingerprint);
 +            }});
          response.matches = matches.toArray(new QueryResponse.Match[0]);

 }}}

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/24327#comment:2>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the metrics-bugs mailing list