[tor-commits] [onionoo/master] Simplify getStatsString methods.
karsten at torproject.org
karsten at torproject.org
Wed Nov 20 11:52:23 UTC 2019
commit f0530196ab111ebad5862561b6617346fb52a256
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Wed Nov 20 12:36:18 2019 +0100
Simplify getStatsString methods.
---
.../metrics/onionoo/docs/DocumentStore.java | 32 ++++++++++------------
.../onionoo/updater/ClientsStatusUpdater.java | 13 ++++-----
.../metrics/onionoo/updater/LookupService.java | 11 ++++----
.../onionoo/updater/NodeDetailsStatusUpdater.java | 10 +++----
.../onionoo/updater/UptimeStatusUpdater.java | 18 +++++-------
.../onionoo/writer/ClientsDocumentWriter.java | 6 ++--
.../onionoo/writer/SummaryDocumentWriter.java | 10 +++----
.../onionoo/writer/UptimeDocumentWriter.java | 6 ++--
8 files changed, 43 insertions(+), 63 deletions(-)
diff --git a/src/main/java/org/torproject/metrics/onionoo/docs/DocumentStore.java b/src/main/java/org/torproject/metrics/onionoo/docs/DocumentStore.java
index 78c0baa..9489cba 100644
--- a/src/main/java/org/torproject/metrics/onionoo/docs/DocumentStore.java
+++ b/src/main/java/org/torproject/metrics/onionoo/docs/DocumentStore.java
@@ -817,24 +817,20 @@ public class DocumentStore {
/** Returns a string with statistics on document storage operations. */
public String getStatsString() {
- StringBuilder sb = new StringBuilder();
- sb.append(" ")
- .append(FormattingUtils.formatDecimalNumber(listOperations))
- .append(" list operations performed\n");
- sb.append(" ").append(FormattingUtils.formatDecimalNumber(listedFiles))
- .append(" files listed\n");
- sb.append(" ").append(FormattingUtils.formatDecimalNumber(storedFiles))
- .append(" files stored\n");
- sb.append(" ").append(FormattingUtils.formatBytes(storedBytes))
- .append(" stored\n");
- sb.append(" ")
- .append(FormattingUtils.formatDecimalNumber(retrievedFiles))
- .append(" files retrieved\n");
- sb.append(" ").append(FormattingUtils.formatBytes(retrievedBytes))
- .append(" retrieved\n");
- sb.append(" ").append(FormattingUtils.formatDecimalNumber(removedFiles))
- .append(" files removed\n");
- return sb.toString();
+ return String.format(" %s list operations performed\n"
+ + " %s files listed\n"
+ + " %s files stored\n"
+ + " %s stored\n"
+ + " %s files retrieved\n"
+ + " %s retrieved\n"
+ + " %s files removed\n",
+ FormattingUtils.formatDecimalNumber(listOperations),
+ FormattingUtils.formatDecimalNumber(listedFiles),
+ FormattingUtils.formatDecimalNumber(storedFiles),
+ FormattingUtils.formatBytes(storedBytes),
+ FormattingUtils.formatDecimalNumber(retrievedFiles),
+ FormattingUtils.formatBytes(retrievedBytes),
+ FormattingUtils.formatDecimalNumber(removedFiles));
}
}
diff --git a/src/main/java/org/torproject/metrics/onionoo/updater/ClientsStatusUpdater.java b/src/main/java/org/torproject/metrics/onionoo/updater/ClientsStatusUpdater.java
index fdaa39c..07dfb85 100644
--- a/src/main/java/org/torproject/metrics/onionoo/updater/ClientsStatusUpdater.java
+++ b/src/main/java/org/torproject/metrics/onionoo/updater/ClientsStatusUpdater.java
@@ -172,14 +172,11 @@ public class ClientsStatusUpdater implements DescriptorListener,
for (SortedSet<ClientsHistory> hist : this.newResponses.values()) {
newIntervals += hist.size();
}
- StringBuilder sb = new StringBuilder();
- sb.append(" ")
- .append(FormattingUtils.formatDecimalNumber(newIntervals / 2))
- .append(" client statistics processed from extra-info descriptors\n");
- sb.append(" ")
- .append(FormattingUtils.formatDecimalNumber(this.newResponses.size()))
- .append(" client status files updated\n");
- return sb.toString();
+ return String.format(
+ " %s client statistics processed from extra-info descriptors\n"
+ + " %s client status files updated\n",
+ FormattingUtils.formatDecimalNumber(newIntervals / 2),
+ FormattingUtils.formatDecimalNumber(this.newResponses.size()));
}
}
diff --git a/src/main/java/org/torproject/metrics/onionoo/updater/LookupService.java b/src/main/java/org/torproject/metrics/onionoo/updater/LookupService.java
index 63fcaa8..9e97487 100644
--- a/src/main/java/org/torproject/metrics/onionoo/updater/LookupService.java
+++ b/src/main/java/org/torproject/metrics/onionoo/updater/LookupService.java
@@ -358,12 +358,11 @@ public class LookupService {
/** Returns a string with the number of addresses looked up and
* resolved. */
public String getStatsString() {
- StringBuilder sb = new StringBuilder();
- sb.append(" ").append(FormattingUtils.formatDecimalNumber(
- addressesLookedUp)).append(" addresses looked up\n");
- sb.append(" ").append(FormattingUtils.formatDecimalNumber(
- addressesResolved)).append(" addresses resolved\n");
- return sb.toString();
+ return String.format(
+ " %s addresses looked up\n"
+ + " %s addresses resolved\n",
+ FormattingUtils.formatDecimalNumber(addressesLookedUp),
+ FormattingUtils.formatDecimalNumber(addressesResolved));
}
}
diff --git a/src/main/java/org/torproject/metrics/onionoo/updater/NodeDetailsStatusUpdater.java b/src/main/java/org/torproject/metrics/onionoo/updater/NodeDetailsStatusUpdater.java
index b25459d..9718202 100644
--- a/src/main/java/org/torproject/metrics/onionoo/updater/NodeDetailsStatusUpdater.java
+++ b/src/main/java/org/torproject/metrics/onionoo/updater/NodeDetailsStatusUpdater.java
@@ -951,12 +951,10 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
@Override
public String getStatsString() {
- StringBuilder sb = new StringBuilder();
- sb.append(" ").append(FormattingUtils.formatDecimalNumber(
- relayConsensusesProcessed)).append(" relay consensuses processed\n");
- sb.append(" ").append(FormattingUtils.formatDecimalNumber(
- bridgeStatusesProcessed)).append(" bridge statuses processed\n");
- return sb.toString();
+ return String.format(" %s relay consensuses processed\n"
+ + " %s bridge statuses processed\n",
+ FormattingUtils.formatDecimalNumber(relayConsensusesProcessed),
+ FormattingUtils.formatDecimalNumber(bridgeStatusesProcessed));
}
}
diff --git a/src/main/java/org/torproject/metrics/onionoo/updater/UptimeStatusUpdater.java b/src/main/java/org/torproject/metrics/onionoo/updater/UptimeStatusUpdater.java
index 584d24d..1f9f960 100644
--- a/src/main/java/org/torproject/metrics/onionoo/updater/UptimeStatusUpdater.java
+++ b/src/main/java/org/torproject/metrics/onionoo/updater/UptimeStatusUpdater.java
@@ -176,17 +176,13 @@ public class UptimeStatusUpdater implements DescriptorListener,
@Override
public String getStatsString() {
- StringBuilder sb = new StringBuilder();
- sb.append(" ").append(FormattingUtils.formatDecimalNumber(
- this.newRelayStatuses.size())).append(" hours of relay uptimes ")
- .append("processed\n");
- sb.append(" ").append(FormattingUtils.formatDecimalNumber(
- this.newBridgeStatuses.size())).append(" hours of bridge uptimes ")
- .append("processed\n");
- sb.append(" ").append(FormattingUtils.formatDecimalNumber(
- this.newRunningRelays.size() + this.newRunningBridges.size()))
- .append(" uptime status files updated\n");
- return sb.toString();
+ return String.format(" %s hours of relay uptimes processed\n"
+ + " %s hours of bridge uptimes processed\n"
+ + " %s uptime status files updated\n",
+ FormattingUtils.formatDecimalNumber(this.newRelayStatuses.size()),
+ FormattingUtils.formatDecimalNumber(this.newBridgeStatuses.size()),
+ FormattingUtils.formatDecimalNumber(
+ this.newRunningRelays.size() + this.newRunningBridges.size()));
}
}
diff --git a/src/main/java/org/torproject/metrics/onionoo/writer/ClientsDocumentWriter.java b/src/main/java/org/torproject/metrics/onionoo/writer/ClientsDocumentWriter.java
index b1406ac..e253d22 100644
--- a/src/main/java/org/torproject/metrics/onionoo/writer/ClientsDocumentWriter.java
+++ b/src/main/java/org/torproject/metrics/onionoo/writer/ClientsDocumentWriter.java
@@ -113,10 +113,8 @@ public class ClientsDocumentWriter implements DocumentWriter {
@Override
public String getStatsString() {
- StringBuilder sb = new StringBuilder();
- sb.append(" ").append(FormattingUtils.formatDecimalNumber(
- this.writtenDocuments)).append(" clients document files updated\n");
- return sb.toString();
+ return String.format(" %s clients document files updated\n",
+ FormattingUtils.formatDecimalNumber(this.writtenDocuments));
}
}
diff --git a/src/main/java/org/torproject/metrics/onionoo/writer/SummaryDocumentWriter.java b/src/main/java/org/torproject/metrics/onionoo/writer/SummaryDocumentWriter.java
index 0103c31..997fe40 100644
--- a/src/main/java/org/torproject/metrics/onionoo/writer/SummaryDocumentWriter.java
+++ b/src/main/java/org/torproject/metrics/onionoo/writer/SummaryDocumentWriter.java
@@ -113,12 +113,10 @@ public class SummaryDocumentWriter implements DocumentWriter {
@Override
public String getStatsString() {
- StringBuilder sb = new StringBuilder();
- sb.append(" ").append(FormattingUtils.formatDecimalNumber(
- this.writtenDocuments)).append(" summary document files written\n");
- sb.append(" ").append(FormattingUtils.formatDecimalNumber(
- this.deletedDocuments)).append(" summary document files deleted\n");
- return sb.toString();
+ return String.format(" %s summary document files written\n"
+ + " %s summary document files deleted\n",
+ FormattingUtils.formatDecimalNumber(this.writtenDocuments),
+ FormattingUtils.formatDecimalNumber(this.deletedDocuments));
}
}
diff --git a/src/main/java/org/torproject/metrics/onionoo/writer/UptimeDocumentWriter.java b/src/main/java/org/torproject/metrics/onionoo/writer/UptimeDocumentWriter.java
index fc9b08a..e2a0f63 100644
--- a/src/main/java/org/torproject/metrics/onionoo/writer/UptimeDocumentWriter.java
+++ b/src/main/java/org/torproject/metrics/onionoo/writer/UptimeDocumentWriter.java
@@ -238,10 +238,8 @@ public class UptimeDocumentWriter implements DocumentWriter {
@Override
public String getStatsString() {
- StringBuilder sb = new StringBuilder();
- sb.append(" ").append(FormattingUtils.formatDecimalNumber(
- this.writtenDocuments)).append(" uptime document files written\n");
- return sb.toString();
+ return String.format(" %s uptime document files written\n",
+ FormattingUtils.formatDecimalNumber(this.writtenDocuments));
}
}
More information about the tor-commits
mailing list