[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [onionoo/master] Make information that is only depending on enums part of these enums.
commit 41e9daed85923b45726dde1887843a44ca3ad3a1
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date: Fri Mar 31 13:12:42 2017 +0000
Make information that is only depending on enums part of these enums.
---
.../onionoo/updater/DescriptorHistory.java | 30 +++++++---
.../onionoo/updater/DescriptorQueue.java | 70 +---------------------
.../torproject/onionoo/updater/DescriptorType.java | 24 +++++---
3 files changed, 41 insertions(+), 83 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/updater/DescriptorHistory.java b/src/main/java/org/torproject/onionoo/updater/DescriptorHistory.java
index ae47c0c..238546a 100644
--- a/src/main/java/org/torproject/onionoo/updater/DescriptorHistory.java
+++ b/src/main/java/org/torproject/onionoo/updater/DescriptorHistory.java
@@ -3,14 +3,26 @@
package org.torproject.onionoo.updater;
-enum DescriptorHistory {
- RELAY_CONSENSUS_HISTORY,
- RELAY_SERVER_HISTORY,
- RELAY_EXTRAINFO_HISTORY,
- EXIT_LIST_HISTORY,
- BRIDGE_STATUS_HISTORY,
- BRIDGE_SERVER_HISTORY,
- BRIDGE_EXTRAINFO_HISTORY,
- ARCHIVED_HISTORY
+public enum DescriptorHistory {
+
+ RELAY_CONSENSUS_HISTORY("relay-consensus-history"),
+ RELAY_SERVER_HISTORY("relay-server-history"),
+ RELAY_EXTRAINFO_HISTORY("relay-extrainfo-history"),
+ EXIT_LIST_HISTORY("exit-list-history"),
+ BRIDGE_STATUS_HISTORY("bridge-status-history"),
+ BRIDGE_SERVER_HISTORY("bridge-server-history"),
+ BRIDGE_EXTRAINFO_HISTORY("bridge-extrainfo-history"),
+ ARCHIVED_HISTORY("archived-history");
+
+ private String fileName;
+
+ private DescriptorHistory(String fileName) {
+ this.fileName = fileName;
+ }
+
+ public String getFileName() {
+ return this.fileName;
+ }
+
}
diff --git a/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java b/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java
index 92817b1..e2657c9 100644
--- a/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java
+++ b/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java
@@ -66,8 +66,7 @@ class DescriptorQueue {
File statusDir) {
File directory = inDir;
if (descriptorType != null) {
- directory = this.getDirectoryForDescriptorType(inDir,
- descriptorType);
+ directory = new File(inDir, descriptorType.getDir());
}
this.statusDir = statusDir;
this.descriptorReader =
@@ -75,39 +74,6 @@ class DescriptorQueue {
this.addDirectory(directory);
}
- public File getDirectoryForDescriptorType(File inDir,
- DescriptorType descriptorType) {
- String directoryName = null;
- switch (descriptorType) {
- case RELAY_CONSENSUSES:
- directoryName = "relay-descriptors/consensuses";
- break;
- case RELAY_SERVER_DESCRIPTORS:
- directoryName = "relay-descriptors/server-descriptors";
- break;
- case RELAY_EXTRA_INFOS:
- directoryName = "relay-descriptors/extra-infos";
- break;
- case BRIDGE_STATUSES:
- directoryName = "bridge-descriptors/statuses";
- break;
- case BRIDGE_SERVER_DESCRIPTORS:
- directoryName = "bridge-descriptors/server-descriptors";
- break;
- case BRIDGE_EXTRA_INFOS:
- directoryName = "bridge-descriptors/extra-infos";
- break;
- case EXIT_LISTS:
- directoryName = "exit-lists";
- break;
- default:
- log.error("Unknown descriptor type. Not adding directory "
- + "to descriptor reader.");
- return null;
- }
- return new File(inDir, directoryName);
- }
-
private void addDirectory(File directory) {
if (directory == null) {
return;
@@ -126,38 +92,8 @@ class DescriptorQueue {
if (this.statusDir == null) {
return;
}
- String historyFileName = null;
- switch (descriptorHistory) {
- case RELAY_EXTRAINFO_HISTORY:
- historyFileName = "relay-extrainfo-history";
- break;
- case BRIDGE_EXTRAINFO_HISTORY:
- historyFileName = "bridge-extrainfo-history";
- break;
- case EXIT_LIST_HISTORY:
- historyFileName = "exit-list-history";
- break;
- case RELAY_CONSENSUS_HISTORY:
- historyFileName = "relay-consensus-history";
- break;
- case BRIDGE_STATUS_HISTORY:
- historyFileName = "bridge-status-history";
- break;
- case RELAY_SERVER_HISTORY:
- historyFileName = "relay-server-history";
- break;
- case BRIDGE_SERVER_HISTORY:
- historyFileName = "bridge-server-history";
- break;
- case ARCHIVED_HISTORY:
- historyFileName = "archived-history";
- break;
- default:
- log.error("Unknown descriptor history. Not excluding "
- + "files.");
- return;
- }
- this.historyFile = new File(this.statusDir, historyFileName);
+ this.historyFile = new File(this.statusDir,
+ descriptorHistory.getFileName());
if (this.historyFile.exists() && this.historyFile.isFile()) {
SortedMap<String, Long> excludedFiles = new TreeMap<>();
try (BufferedReader br = new BufferedReader(new FileReader(
diff --git a/src/main/java/org/torproject/onionoo/updater/DescriptorType.java b/src/main/java/org/torproject/onionoo/updater/DescriptorType.java
index f9a266e..6647a51 100644
--- a/src/main/java/org/torproject/onionoo/updater/DescriptorType.java
+++ b/src/main/java/org/torproject/onionoo/updater/DescriptorType.java
@@ -4,12 +4,22 @@
package org.torproject.onionoo.updater;
public enum DescriptorType {
- RELAY_CONSENSUSES,
- RELAY_SERVER_DESCRIPTORS,
- RELAY_EXTRA_INFOS,
- EXIT_LISTS,
- BRIDGE_STATUSES,
- BRIDGE_SERVER_DESCRIPTORS,
- BRIDGE_EXTRA_INFOS,
+ RELAY_CONSENSUSES("relay-descriptors/consensuses"),
+ RELAY_SERVER_DESCRIPTORS("relay-descriptors/server-descriptors"),
+ RELAY_EXTRA_INFOS("relay-descriptors/extra-infos"),
+ EXIT_LISTS("exit-lists"),
+ BRIDGE_STATUSES("bridge-descriptors/statuses"),
+ BRIDGE_SERVER_DESCRIPTORS("bridge-descriptors/server-descriptors"),
+ BRIDGE_EXTRA_INFOS("bridge-descriptors/extra-infos");
+
+ private final String dir;
+ private DescriptorType(String dir) {
+ this.dir = dir;
+ }
+
+ public String getDir() {
+ return this.dir;
+ }
+
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits