[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [collector/master] Use more powerful Map methods.



commit 013370a0088a04d521e43f1a298d0947315462d8
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Mon Aug 20 15:21:58 2018 +0200

    Use more powerful Map methods.
---
 .../metrics/collector/relaydescs/ArchiveWriter.java         |  3 +--
 .../torproject/metrics/collector/webstats/LogFileMap.java   | 13 +++----------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveWriter.java b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveWriter.java
index 98d2864..08874b9 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveWriter.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveWriter.java
@@ -427,8 +427,7 @@ public class ArchiveWriter extends CollecTorMain {
         }
       }
       sb.append("\nC, " + validAfterTime);
-      int allVotes = this.expectedVotes.containsKey(validAfterMillis)
-          ? this.expectedVotes.get(validAfterMillis) : 0;
+      int allVotes = this.expectedVotes.getOrDefault(validAfterMillis, 0);
       if (allVotes > 0) {
         sb.append(String.format(", %d/%d V (%.1f%%)", foundVotes, allVotes,
             100.0D * (double) foundVotes / (double) allVotes));
diff --git a/src/main/java/org/torproject/metrics/collector/webstats/LogFileMap.java b/src/main/java/org/torproject/metrics/collector/webstats/LogFileMap.java
index b265e4b..6d9e22d 100644
--- a/src/main/java/org/torproject/metrics/collector/webstats/LogFileMap.java
+++ b/src/main/java/org/torproject/metrics/collector/webstats/LogFileMap.java
@@ -70,17 +70,10 @@ public class LogFileMap
   /** Add log metadata to the map structure. */
   public void add(LogMetadata metadata) {
     TreeMap<String, TreeMap<LocalDate, LogMetadata>> virtualHosts
-        = this.get(metadata.virtualHost);
-    if (null == virtualHosts) {
-      virtualHosts = new TreeMap<>();
-      this.put(metadata.virtualHost, virtualHosts);
-    }
+        = this.computeIfAbsent(metadata.virtualHost, k -> new TreeMap<>());
     TreeMap<LocalDate, LogMetadata> physicalHosts
-        = virtualHosts.get(metadata.physicalHost);
-    if (null == physicalHosts) {
-      physicalHosts = new TreeMap<>();
-      virtualHosts.put(metadata.physicalHost, physicalHosts);
-    }
+        = virtualHosts.computeIfAbsent(metadata.physicalHost,
+          k -> new TreeMap<>());
     physicalHosts.put(metadata.date, metadata);
   }
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits