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

[tor-commits] [collector/master] Use Java 5 and 7 idioms in more places.



commit 3ba8bdcc16b3bf9ec24eed8a44b981a069092879
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Mon Aug 20 12:21:11 2018 +0200

    Use Java 5 and 7 idioms in more places.
---
 .../bridgedescs/SanitizedBridgesWriter.java         |  3 +--
 .../metrics/collector/conf/Configuration.java       |  4 ++--
 .../metrics/collector/relaydescs/ArchiveReader.java |  2 +-
 .../metrics/collector/relaydescs/ArchiveWriter.java | 21 +++++++--------------
 .../collector/relaydescs/ReferenceChecker.java      |  7 ++-----
 .../relaydescs/RelayDescriptorDownloader.java       |  4 ++--
 .../collector/relaydescs/RelayDescriptorParser.java |  5 +----
 .../metrics/collector/webstats/LogFileMap.java      |  4 ++--
 8 files changed, 18 insertions(+), 32 deletions(-)

diff --git a/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java b/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java
index 305c09a..6511e66 100644
--- a/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java
+++ b/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java
@@ -307,8 +307,7 @@ public class SanitizedBridgesWriter extends CollecTorMain {
           /* Invalid IPv6 address. */
           return null;
         }
-        for (int i = 0; i < parts.length; i++) {
-          String part = parts[i];
+        for (String part : parts) {
           if (part.contains(".")) {
             String[] ipParts = part.split("\\.");
             byte[] ipv4Bytes = new byte[4];
diff --git a/src/main/java/org/torproject/metrics/collector/conf/Configuration.java b/src/main/java/org/torproject/metrics/collector/conf/Configuration.java
index 503ebbf..6f38c45 100644
--- a/src/main/java/org/torproject/metrics/collector/conf/Configuration.java
+++ b/src/main/java/org/torproject/metrics/collector/conf/Configuration.java
@@ -263,8 +263,8 @@ public class Configuration extends Observable implements Cloneable {
     try {
       checkClass(key, SourceType[].class);
       String[] interim = props.getProperty(key.name()).split(FIELDSEP);
-      for (int i = 0; i < interim.length; i++) {
-        SourceType st = SourceType.valueOf(interim[i].trim());
+      for (String anInterim : interim) {
+        SourceType st = SourceType.valueOf(anInterim.trim());
         if (null == res) {
           res = EnumSet.of(st);
         } else {
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java
index 84ad2b6..0119aef 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java
@@ -276,7 +276,7 @@ public class ArchiveReader {
       if (!this.microdescriptorValidAfterTimes.containsKey(
           microdescriptor)) {
         this.microdescriptorValidAfterTimes.put(microdescriptor,
-            new HashSet<String>());
+            new HashSet<>());
       }
       this.microdescriptorValidAfterTimes.get(microdescriptor).add(
           validAfterTime);
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 11388f2..31dfdef 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveWriter.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveWriter.java
@@ -230,8 +230,7 @@ public class ArchiveWriter extends CollecTorMain {
             continue;
           }
           if (!this.storedServerDescriptors.containsKey(published)) {
-            this.storedServerDescriptors.put(published,
-                new HashMap<String, String>());
+            this.storedServerDescriptors.put(published, new HashMap<>());
           }
           String serverDescriptorDigest = parts[1];
           String extraInfoDescriptorDigest = parts[2].equals("NA") ? null
@@ -259,8 +258,7 @@ public class ArchiveWriter extends CollecTorMain {
             continue;
           }
           if (!this.storedExtraInfoDescriptors.containsKey(published)) {
-            this.storedExtraInfoDescriptors.put(published,
-                new HashSet<String>());
+            this.storedExtraInfoDescriptors.put(published, new HashSet<>());
           }
           String extraInfoDescriptorDigest = parts[1];
           this.storedExtraInfoDescriptors.get(published).add(
@@ -286,8 +284,7 @@ public class ArchiveWriter extends CollecTorMain {
             continue;
           }
           if (!this.storedMicrodescriptors.containsKey(validAfter)) {
-            this.storedMicrodescriptors.put(validAfter,
-                new HashSet<String>());
+            this.storedMicrodescriptors.put(validAfter, new HashSet<>());
           }
           String microdescriptorDigest = parts[1];
           this.storedMicrodescriptors.get(validAfter).add(
@@ -706,8 +703,7 @@ public class ArchiveWriter extends CollecTorMain {
     if (!tarballFileExistedBefore
         && this.now - validAfter < 3L * 60L * 60L * 1000L) {
       if (!this.storedVotes.containsKey(validAfter)) {
-        this.storedVotes.put(validAfter,
-            new TreeMap<String, SortedSet<String>>());
+        this.storedVotes.put(validAfter, new TreeMap<>());
       }
       this.storedVotes.get(validAfter).put(fingerprint,
           serverDescriptorDigests);
@@ -750,8 +746,7 @@ public class ArchiveWriter extends CollecTorMain {
     if (!tarballFileExistedBefore
         && this.now - published < 48L * 60L * 60L * 1000L) {
       if (!this.storedServerDescriptors.containsKey(published)) {
-        this.storedServerDescriptors.put(published,
-            new HashMap<String, String>());
+        this.storedServerDescriptors.put(published, new HashMap<>());
       }
       this.storedServerDescriptors.get(published).put(digest,
           extraInfoDigest);
@@ -779,8 +774,7 @@ public class ArchiveWriter extends CollecTorMain {
     if (!tarballFileExistedBefore
         && this.now - published < 48L * 60L * 60L * 1000L) {
       if (!this.storedExtraInfoDescriptors.containsKey(published)) {
-        this.storedExtraInfoDescriptors.put(published,
-            new HashSet<String>());
+        this.storedExtraInfoDescriptors.put(published, new HashSet<>());
       }
       this.storedExtraInfoDescriptors.get(published).add(extraInfoDigest);
     }
@@ -815,8 +809,7 @@ public class ArchiveWriter extends CollecTorMain {
     if (!tarballFileExistedBefore
         && this.now - validAfter < 40L * 24L * 60L * 60L * 1000L) {
       if (!this.storedMicrodescriptors.containsKey(validAfter)) {
-        this.storedMicrodescriptors.put(validAfter,
-            new HashSet<String>());
+        this.storedMicrodescriptors.put(validAfter, new HashSet<>());
       }
       this.storedMicrodescriptors.get(validAfter).add(
           microdescriptorDigest);
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/ReferenceChecker.java b/src/main/java/org/torproject/metrics/collector/relaydescs/ReferenceChecker.java
index 83b3ae9..0984de0 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/ReferenceChecker.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/ReferenceChecker.java
@@ -28,7 +28,6 @@ import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Locale;
 import java.util.Set;
 import java.util.SortedSet;
@@ -170,10 +169,8 @@ public class ReferenceChecker {
     DescriptorReader descriptorReader =
         DescriptorSourceFactory.createDescriptorReader();
     descriptorReader.setHistoryFile(this.historyFile);
-    Iterator<Descriptor> descriptors
-        = descriptorReader.readDescriptors(this.descriptorsDir).iterator();
-    while (descriptors.hasNext()) {
-      Descriptor descriptor = descriptors.next();
+    for (Descriptor descriptor
+        : descriptorReader.readDescriptors(this.descriptorsDir)) {
       if (descriptor instanceof RelayNetworkStatusConsensus) {
         RelayNetworkStatusConsensus consensus =
             (RelayNetworkStatusConsensus) descriptor;
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java
index e1dff40..cf9ebc4 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java
@@ -383,7 +383,7 @@ public class RelayDescriptorDownloader {
                 if (!this.microdescriptorKeys.containsKey(
                     microdescriptorDigest)) {
                   this.microdescriptorKeys.put(
-                      microdescriptorDigest, new HashSet<String>());
+                      microdescriptorDigest, new HashSet<>());
                 }
                 this.microdescriptorKeys.get(microdescriptorDigest).add(
                     microdescriptorKey);
@@ -552,7 +552,7 @@ public class RelayDescriptorDownloader {
           }
         } else {
           this.microdescriptorKeys.put(
-              microdescriptorDigest, new HashSet<String>());
+              microdescriptorDigest, new HashSet<>());
         }
         this.microdescriptorKeys.get(microdescriptorDigest).add(
             microdescriptorKey);
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java
index 74e0ce9..65e2e2e 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java
@@ -316,10 +316,7 @@ public class RelayDescriptorParser {
          * storeMicrodescriptor below. */
       }
       br.close();
-    } catch (IOException e) {
-      logger.warn("Could not parse descriptor. "
-          + "Skipping.", e);
-    } catch (ParseException e) {
+    } catch (IOException | ParseException e) {
       logger.warn("Could not parse descriptor. "
           + "Skipping.", e);
     }
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 0d23f9a..7fa3970 100644
--- a/src/main/java/org/torproject/metrics/collector/webstats/LogFileMap.java
+++ b/src/main/java/org/torproject/metrics/collector/webstats/LogFileMap.java
@@ -75,13 +75,13 @@ public class LogFileMap
     TreeMap<String, TreeMap<LocalDate, LogMetadata>> virtualHosts
         = this.get(metadata.virtualHost);
     if (null == virtualHosts) {
-      virtualHosts = new TreeMap<String, TreeMap<LocalDate, LogMetadata>>();
+      virtualHosts = new TreeMap<>();
       this.put(metadata.virtualHost, virtualHosts);
     }
     TreeMap<LocalDate, LogMetadata> physicalHosts
         = virtualHosts.get(metadata.physicalHost);
     if (null == physicalHosts) {
-      physicalHosts = new TreeMap<LocalDate, LogMetadata>();
+      physicalHosts = new TreeMap<>();
       virtualHosts.put(metadata.physicalHost, physicalHosts);
     }
     physicalHosts.put(metadata.date, metadata);



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