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

[tor-commits] [collector/master] Replace if with switch.



commit 5080bf9907d3b8e3e3238b9abcf3786a1742ee32
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Tue Aug 21 12:22:57 2018 +0200

    Replace if with switch.
---
 .../relaydescs/RelayDescriptorDownloader.java      |  37 ++++---
 .../relaydescs/RelayDescriptorParser.java          | 106 +++++++++++----------
 2 files changed, 77 insertions(+), 66 deletions(-)

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 6e470d8..564d1bc 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java
@@ -812,21 +812,28 @@ public class RelayDescriptorDownloader {
                   this.downloadResourceFromAuthority(authority,
                   combinedResource.toString());
             }
-            if (type.equals("server")) {
-              this.requestedMissingServerDescriptors +=
-                  requestedDescriptors;
-              this.downloadedMissingServerDescriptors +=
-                  downloadedDescriptors;
-            } else if (type.equals("extra")) {
-              this.requestedMissingExtraInfoDescriptors +=
-                  requestedDescriptors;
-              this.downloadedMissingExtraInfoDescriptors +=
-                  downloadedDescriptors;
-            } else if (type.equals("micro")) {
-              this.requestedMissingMicrodescriptors +=
-                  requestedDescriptors;
-              this.downloadedMissingMicrodescriptors +=
-                  downloadedDescriptors;
+            switch (type) {
+              case "server":
+                this.requestedMissingServerDescriptors +=
+                    requestedDescriptors;
+                this.downloadedMissingServerDescriptors +=
+                    downloadedDescriptors;
+                break;
+              case "extra":
+                this.requestedMissingExtraInfoDescriptors +=
+                    requestedDescriptors;
+                this.downloadedMissingExtraInfoDescriptors +=
+                    downloadedDescriptors;
+                break;
+              case "micro":
+                this.requestedMissingMicrodescriptors +=
+                    requestedDescriptors;
+                this.downloadedMissingMicrodescriptors +=
+                    downloadedDescriptors;
+                break;
+              default:
+                /* Unknown type, nothing to do. */
+                break;
             }
           }
         }
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 59b9fb0..5224a61 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java
@@ -175,60 +175,64 @@ public class RelayDescriptorParser {
             }
           }
         }
-        if (statusType.equals("consensus")) {
-          if (this.rdd != null) {
-            this.rdd.haveParsedConsensus(validAfterTime, dirSources,
-                serverDescriptors);
-          }
-          if (this.aw != null) {
-            this.aw.storeConsensus(data, validAfter, dirSources,
-                serverDescriptorDigests);
-            stored = true;
-          }
-        } else if (statusType.equals("consensus-microdesc")) {
-          if (this.rdd != null) {
-            this.rdd.haveParsedMicrodescConsensus(validAfterTime,
-                microdescriptorKeys);
-          }
-          if (this.ar != null) {
-            this.ar.haveParsedMicrodescConsensus(validAfterTime,
-                microdescriptorDigests);
-          }
-          if (this.aw != null) {
-            this.aw.storeMicrodescConsensus(data, validAfter,
-                microdescriptorDigests);
-            stored = true;
-          }
-        } else {
-          if (this.aw != null || this.rdd != null) {
-            String ascii = new String(data, "US-ASCII");
-            String startToken = "network-status-version ";
-            String sigToken = "directory-signature ";
-            int start = ascii.indexOf(startToken);
-            int sig = ascii.indexOf(sigToken);
-            if (start >= 0 && sig >= 0 && sig > start) {
-              sig += sigToken.length();
-              byte[] forDigest = new byte[sig - start];
-              System.arraycopy(data, start, forDigest, 0, sig - start);
-              String digest = DigestUtils.sha1Hex(forDigest).toUpperCase();
-              if (this.aw != null) {
-                this.aw.storeVote(data, validAfter, dirSource, digest,
-                    serverDescriptorDigests);
-                stored = true;
-              }
-              if (this.rdd != null) {
-                this.rdd.haveParsedVote(validAfterTime, fingerprint,
-                    serverDescriptors);
-              }
+        switch (statusType) {
+          case "consensus":
+            if (this.rdd != null) {
+              this.rdd.haveParsedConsensus(validAfterTime, dirSources,
+                  serverDescriptors);
             }
-            if (certificateString != null) {
-              if (this.aw != null) {
-                this.aw.storeCertificate(certificateString.getBytes(),
-                    dirSource, dirKeyPublished);
-                stored = true;
+            if (this.aw != null) {
+              this.aw.storeConsensus(data, validAfter, dirSources,
+                  serverDescriptorDigests);
+              stored = true;
+            }
+            break;
+          case "consensus-microdesc":
+            if (this.rdd != null) {
+              this.rdd.haveParsedMicrodescConsensus(validAfterTime,
+                  microdescriptorKeys);
+            }
+            if (this.ar != null) {
+              this.ar.haveParsedMicrodescConsensus(validAfterTime,
+                  microdescriptorDigests);
+            }
+            if (this.aw != null) {
+              this.aw.storeMicrodescConsensus(data, validAfter,
+                  microdescriptorDigests);
+              stored = true;
+            }
+            break;
+          default:
+            if (this.aw != null || this.rdd != null) {
+              String ascii = new String(data, "US-ASCII");
+              String startToken = "network-status-version ";
+              String sigToken = "directory-signature ";
+              int start = ascii.indexOf(startToken);
+              int sig = ascii.indexOf(sigToken);
+              if (start >= 0 && sig >= 0 && sig > start) {
+                sig += sigToken.length();
+                byte[] forDigest = new byte[sig - start];
+                System.arraycopy(data, start, forDigest, 0, sig - start);
+                String digest = DigestUtils.sha1Hex(forDigest).toUpperCase();
+                if (this.aw != null) {
+                  this.aw.storeVote(data, validAfter, dirSource, digest,
+                      serverDescriptorDigests);
+                  stored = true;
+                }
+                if (this.rdd != null) {
+                  this.rdd.haveParsedVote(validAfterTime, fingerprint,
+                      serverDescriptors);
+                }
+              }
+              if (certificateString != null) {
+                if (this.aw != null) {
+                  this.aw.storeCertificate(certificateString.getBytes(),
+                      dirSource, dirKeyPublished);
+                  stored = true;
+                }
               }
             }
-          }
+            break;
         }
       } else if (line.startsWith("router ")) {
         String publishedTime = null;



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