#16553: Add support for searching by (partial) host name -----------------------------+-------------------------------- Reporter: karsten | Owner: metrics-team Type: enhancement | Status: needs_revision Priority: Very Low | Milestone: Onionoo-1.7.0 Component: Metrics/Onionoo | Version: Severity: Normal | Resolution: Keywords: metrics-2018 | Actual Points: Parent ID: | Points: Reviewer: | Sponsor: -----------------------------+--------------------------------
Comment (by iwakeh): Replying to [comment:19 karsten]: > I'll work on the checkstyle complaints (oops!) and on renaming variables. > > Regarding that Java 8 idiom, do you know whether it's possible to rewrite that to something that doesn't require a temporary data structure like `removeRelays`? Would be cool to simplify that code and related code in the same class even more. A simplification rather due to using the hostname from the summary doc than to j8: {{{ diff --git a/src/main/java/org/torproject/onionoo/server/RequestHandler.java b/src/main/java/org/torproject/onionoo/server/RequestHandler.java index 23af60b..dd923d4 100644 --- a/src/main/java/org/torproject/onionoo/server/RequestHandler.java +++ b/src/main/java/org/torproject/onionoo/server/RequestHandler.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedMap; +import java.util.stream.Collectors; public class RequestHandler { @@ -550,16 +551,12 @@ public class RequestHandler { return; } String hostName = this.hostName.toLowerCase(); - Set<String> removeRelays = new HashSet<>(this.filteredRelays.keySet()); - for (Map.Entry<String, Set<String>> e : - this.nodeIndex.getRelaysByHostName().entrySet()) { - if (e.getKey().endsWith(hostName)) { - removeRelays.removeAll(e.getValue()); - } - } - for (String fingerprint : removeRelays) { - this.filteredRelays.remove(fingerprint); - } + this.filteredRelays + .entrySet().retainAll(this.filteredRelays.entrySet().stream() + .filter(entry + -> null != entry.getValue().getHostName() + && entry.getValue().getHostName().endsWith(hostName)) + .collect(Collectors.toSet())); this.filteredBridges.clear(); } }}} -- Ticket URL: <https://trac.torproject.org/projects/tor/ticket/16553#comment:22> Tor Bug Tracker & Wiki <https://trac.torproject.org/> The Tor Project: anonymity online
_______________________________________________ tor-bugs mailing list tor-bugs@lists.torproject.org https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-bugs