commit c41454305d62f497d292d19ab933797bfde61310 Author: Karsten Loesing karsten.loesing@gmx.net Date: Mon Aug 20 15:50:23 2018 +0200
Use chained String.append calls. --- .../torproject/onionoo/docs/BandwidthStatus.java | 12 ++++---- .../torproject/onionoo/docs/ClientsHistory.java | 8 ++--- .../org/torproject/onionoo/docs/ClientsStatus.java | 2 +- .../org/torproject/onionoo/docs/DocumentStore.java | 36 ++++++++++++---------- .../org/torproject/onionoo/docs/UptimeHistory.java | 6 ++-- .../org/torproject/onionoo/docs/UptimeStatus.java | 4 +-- .../org/torproject/onionoo/docs/WeightsStatus.java | 4 +-- .../onionoo/server/IntegerDistribution.java | 9 +++--- .../onionoo/server/MostFrequentString.java | 4 +-- .../torproject/onionoo/server/ResponseBuilder.java | 4 +-- .../onionoo/updater/ClientsStatusUpdater.java | 12 ++++---- .../torproject/onionoo/updater/LookupService.java | 8 ++--- .../onionoo/updater/NodeDetailsStatusUpdater.java | 8 ++--- .../onionoo/updater/ReverseDomainNameResolver.java | 30 +++++++++--------- .../onionoo/updater/UptimeStatusUpdater.java | 18 +++++------ .../onionoo/writer/ClientsDocumentWriter.java | 4 +-- .../onionoo/writer/SummaryDocumentWriter.java | 8 ++--- .../onionoo/writer/UptimeDocumentWriter.java | 4 +-- 18 files changed, 92 insertions(+), 89 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/docs/BandwidthStatus.java b/src/main/java/org/torproject/onionoo/docs/BandwidthStatus.java index 252a018..20e2e27 100644 --- a/src/main/java/org/torproject/onionoo/docs/BandwidthStatus.java +++ b/src/main/java/org/torproject/onionoo/docs/BandwidthStatus.java @@ -171,14 +171,14 @@ public class BandwidthStatus extends Document { public String toDocumentString() { StringBuilder sb = new StringBuilder(); for (long[] v : writeHistory.values()) { - sb.append("w " + DateTimeHelper.format(v[0]) + " " - + DateTimeHelper.format(v[1]) + " " + String.valueOf(v[2]) - + "\n"); + sb.append("w ").append(DateTimeHelper.format(v[0])).append(" ") + .append(DateTimeHelper.format(v[1])).append(" ") + .append(String.valueOf(v[2])).append("\n"); } for (long[] v : readHistory.values()) { - sb.append("r " + DateTimeHelper.format(v[0]) + " " - + DateTimeHelper.format(v[1]) + " " + String.valueOf(v[2]) - + "\n"); + sb.append("r ").append(DateTimeHelper.format(v[0])).append(" ") + .append(DateTimeHelper.format(v[1])).append(" ") + .append(String.valueOf(v[2])).append("\n"); } return sb.toString(); } diff --git a/src/main/java/org/torproject/onionoo/docs/ClientsHistory.java b/src/main/java/org/torproject/onionoo/docs/ClientsHistory.java index 15e70c5..58e86e4 100644 --- a/src/main/java/org/torproject/onionoo/docs/ClientsHistory.java +++ b/src/main/java/org/torproject/onionoo/docs/ClientsHistory.java @@ -142,8 +142,8 @@ public class ClientsHistory implements Comparable<ClientsHistory> { public String toString() { StringBuilder sb = new StringBuilder(); sb.append(DateTimeHelper.format(startMillis)); - sb.append(" " + DateTimeHelper.format(endMillis)); - sb.append(" " + String.format("%.3f", this.totalResponses)); + sb.append(" ").append(DateTimeHelper.format(endMillis)); + sb.append(" ").append(String.format("%.3f", this.totalResponses)); this.appendResponses(sb, this.responsesByCountry); this.appendResponses(sb, this.responsesByTransport); this.appendResponses(sb, this.responsesByVersion); @@ -155,8 +155,8 @@ public class ClientsHistory implements Comparable<ClientsHistory> { sb.append(" "); int written = 0; for (Map.Entry<String, Double> e : responses.entrySet()) { - sb.append((written++ > 0 ? "," : "") + e.getKey() + "=" - + String.format("%.3f", e.getValue())); + sb.append(written++ > 0 ? "," : "").append(e.getKey()).append("=") + .append(String.format("%.3f", e.getValue())); } }
diff --git a/src/main/java/org/torproject/onionoo/docs/ClientsStatus.java b/src/main/java/org/torproject/onionoo/docs/ClientsStatus.java index 2e11b50..21a76e1 100644 --- a/src/main/java/org/torproject/onionoo/docs/ClientsStatus.java +++ b/src/main/java/org/torproject/onionoo/docs/ClientsStatus.java @@ -111,7 +111,7 @@ public class ClientsStatus extends Document { public String toDocumentString() { StringBuilder sb = new StringBuilder(); for (ClientsHistory interval : this.history) { - sb.append(interval.toString() + "\n"); + sb.append(interval.toString()).append("\n"); } return sb.toString(); } diff --git a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java index 6efbb52..af67d91 100644 --- a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java +++ b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java @@ -737,7 +737,7 @@ public class DocumentStore { for (NodeStatus relay : cachedRelays.values()) { String line = relay.toString(); if (line != null) { - sb.append(line + "\n"); + sb.append(line).append("\n"); } else { log.error("Could not serialize relay node status '" + relay.getFingerprint() + "'"); @@ -746,7 +746,7 @@ public class DocumentStore { for (NodeStatus bridge : cachedBridges.values()) { String line = bridge.toString(); if (line != null) { - sb.append(line + "\n"); + sb.append(line).append("\n"); } else { log.error("Could not serialize bridge node status '" + bridge.getFingerprint() + "'"); @@ -789,7 +789,7 @@ public class DocumentStore { line = null; } if (line != null) { - sb.append(line + "\n"); + sb.append(line).append("\n"); } else { log.error("Could not serialize relay summary document '" + summaryDocument.getFingerprint() + "'"); @@ -823,20 +823,22 @@ public class DocumentStore { /** Returns a string with statistics on document storage operations. */ public String getStatsString() { StringBuilder sb = new StringBuilder(); - sb.append(" " + FormattingUtils.formatDecimalNumber(listOperations) - + " list operations performed\n"); - sb.append(" " + FormattingUtils.formatDecimalNumber(listedFiles) - + " files listed\n"); - sb.append(" " + FormattingUtils.formatDecimalNumber(storedFiles) - + " files stored\n"); - sb.append(" " + FormattingUtils.formatBytes(storedBytes) - + " stored\n"); - sb.append(" " + FormattingUtils.formatDecimalNumber(retrievedFiles) - + " files retrieved\n"); - sb.append(" " + FormattingUtils.formatBytes(retrievedBytes) - + " retrieved\n"); - sb.append(" " + FormattingUtils.formatDecimalNumber(removedFiles) - + " files removed\n"); + 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(); } } diff --git a/src/main/java/org/torproject/onionoo/docs/UptimeHistory.java b/src/main/java/org/torproject/onionoo/docs/UptimeHistory.java index 3c7f61e..8ddfc2b 100644 --- a/src/main/java/org/torproject/onionoo/docs/UptimeHistory.java +++ b/src/main/java/org/torproject/onionoo/docs/UptimeHistory.java @@ -98,12 +98,12 @@ public class UptimeHistory implements Comparable<UptimeHistory> { public String toString() { StringBuilder sb = new StringBuilder(); sb.append(this.relay ? (this.flags == null ? "r" : "R") : "b"); - sb.append(" " + DateTimeHelper.format(this.startMillis, + sb.append(" ").append(DateTimeHelper.format(this.startMillis, DateTimeHelper.DATEHOUR_NOSPACE_FORMAT)); - sb.append(" " + String.format("%d", this.uptimeHours)); + sb.append(" ").append(String.format("%d", this.uptimeHours)); if (this.flags != null) { for (String flag : this.flags) { - sb.append(" " + flag); + sb.append(" ").append(flag); } } return sb.toString(); diff --git a/src/main/java/org/torproject/onionoo/docs/UptimeStatus.java b/src/main/java/org/torproject/onionoo/docs/UptimeStatus.java index 87ee962..bec5028 100644 --- a/src/main/java/org/torproject/onionoo/docs/UptimeStatus.java +++ b/src/main/java/org/torproject/onionoo/docs/UptimeStatus.java @@ -143,10 +143,10 @@ public class UptimeStatus extends Document { public String toDocumentString() { StringBuilder sb = new StringBuilder(); for (UptimeHistory interval : this.relayHistory) { - sb.append(interval.toString() + "\n"); + sb.append(interval.toString()).append("\n"); } for (UptimeHistory interval : this.bridgeHistory) { - sb.append(interval.toString() + "\n"); + sb.append(interval.toString()).append("\n"); } return sb.toString(); } diff --git a/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java b/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java index adce2c8..f3b5452 100644 --- a/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java +++ b/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java @@ -201,8 +201,8 @@ public class WeightsStatus extends Document { for (Map.Entry<long[], double[]> e : history.entrySet()) { long[] fresh = e.getKey(); double[] weights = e.getValue(); - sb.append(DateTimeHelper.format(fresh[0]) + " " - + DateTimeHelper.format(fresh[1])); + sb.append(DateTimeHelper.format(fresh[0])).append(" ") + .append(DateTimeHelper.format(fresh[1])); for (int i = 0; i < weights.length; i++) { sb.append(" "); if (i != 0 && i != 5 && !Double.valueOf(weights[i]).isNaN()) { diff --git a/src/main/java/org/torproject/onionoo/server/IntegerDistribution.java b/src/main/java/org/torproject/onionoo/server/IntegerDistribution.java index 19862a0..6c1f84d 100644 --- a/src/main/java/org/torproject/onionoo/server/IntegerDistribution.java +++ b/src/main/java/org/torproject/onionoo/server/IntegerDistribution.java @@ -27,9 +27,9 @@ class IntegerDistribution { seenValues += logValues[i]; while (j < permilles.length && (seenValues * 1000 > totalValues * permilles[j])) { - sb.append((j > 0 ? ", " : "") + "." + permilles[j] - + (i < logValues.length - 1 ? "<" + (1L << i) - : ">=" + (1L << i - 1))); + sb.append(j > 0 ? ", " : "").append(".").append(permilles[j]) + .append(i < logValues.length - 1 ? "<" + (1L << i) + : ">=" + (1L << i - 1)); j++; } if (j == permilles.length) { @@ -38,7 +38,8 @@ class IntegerDistribution { } } else { for (int j = 0; j < permilles.length; j++) { - sb.append((j > 0 ? ", " : "") + "." + permilles[j] + "<null"); + sb.append(j > 0 ? ", " : "").append(".").append(permilles[j]) + .append("<null"); } } return sb.toString(); diff --git a/src/main/java/org/torproject/onionoo/server/MostFrequentString.java b/src/main/java/org/torproject/onionoo/server/MostFrequentString.java index c677bb5..dc9bb02 100644 --- a/src/main/java/org/torproject/onionoo/server/MostFrequentString.java +++ b/src/main/java/org/torproject/onionoo/server/MostFrequentString.java @@ -48,8 +48,8 @@ class MostFrequentString { sortedFrequencies.entrySet()) { for (String string : e.getValue()) { if (stringsToAdd-- > 0) { - sb.append((written++ > 0 ? ", " : "") + string + " (" - + e.getKey() + ")"); + sb.append(written++ > 0 ? ", " : "").append(string).append(" (") + .append(e.getKey()).append(")"); } else { remainingStrings.add(string); } diff --git a/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java b/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java index 8b350b0..3d8a76f 100644 --- a/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java +++ b/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java @@ -217,8 +217,8 @@ public class ResponseBuilder { StringBuilder addressesBuilder = new StringBuilder(); int written = 0; for (String address : addresses) { - addressesBuilder.append((written++ > 0 ? "," : "") + """ - + address.toLowerCase() + """); + addressesBuilder.append(written++ > 0 ? "," : "").append(""") + .append(address.toLowerCase()).append("""); } return String.format("{"n":"%s","f":"%s","a":[%s],"r":%s}", nickname, fingerprint, addressesBuilder.toString(), running); diff --git a/src/main/java/org/torproject/onionoo/updater/ClientsStatusUpdater.java b/src/main/java/org/torproject/onionoo/updater/ClientsStatusUpdater.java index 8265f43..205e391 100644 --- a/src/main/java/org/torproject/onionoo/updater/ClientsStatusUpdater.java +++ b/src/main/java/org/torproject/onionoo/updater/ClientsStatusUpdater.java @@ -177,12 +177,12 @@ public class ClientsStatusUpdater implements DescriptorListener, newIntervals += hist.size(); } StringBuilder sb = new StringBuilder(); - sb.append(" " - + FormattingUtils.formatDecimalNumber(newIntervals / 2) - + " client statistics processed from extra-info descriptors\n"); - sb.append(" " - + FormattingUtils.formatDecimalNumber(this.newResponses.size()) - + " client status files updated\n"); + 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(); } } diff --git a/src/main/java/org/torproject/onionoo/updater/LookupService.java b/src/main/java/org/torproject/onionoo/updater/LookupService.java index 4af4443..9c07e68 100644 --- a/src/main/java/org/torproject/onionoo/updater/LookupService.java +++ b/src/main/java/org/torproject/onionoo/updater/LookupService.java @@ -366,10 +366,10 @@ public class LookupService { * resolved. */ public String getStatsString() { StringBuilder sb = new StringBuilder(); - sb.append(" " + FormattingUtils.formatDecimalNumber( - addressesLookedUp) + " addresses looked up\n"); - sb.append(" " + FormattingUtils.formatDecimalNumber( - addressesResolved) + " addresses resolved\n"); + sb.append(" ").append(FormattingUtils.formatDecimalNumber( + addressesLookedUp)).append(" addresses looked up\n"); + sb.append(" ").append(FormattingUtils.formatDecimalNumber( + addressesResolved)).append(" addresses resolved\n"); return sb.toString(); } } diff --git a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java index 82cea1b..054ccf5 100644 --- a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java +++ b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java @@ -958,10 +958,10 @@ public class NodeDetailsStatusUpdater implements DescriptorListener, @Override public String getStatsString() { StringBuilder sb = new StringBuilder(); - sb.append(" " + FormattingUtils.formatDecimalNumber( - relayConsensusesProcessed) + " relay consensuses processed\n"); - sb.append(" " + FormattingUtils.formatDecimalNumber( - bridgeStatusesProcessed) + " bridge statuses processed\n"); + 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(); } } diff --git a/src/main/java/org/torproject/onionoo/updater/ReverseDomainNameResolver.java b/src/main/java/org/torproject/onionoo/updater/ReverseDomainNameResolver.java index d46d6b5..6d48135 100644 --- a/src/main/java/org/torproject/onionoo/updater/ReverseDomainNameResolver.java +++ b/src/main/java/org/torproject/onionoo/updater/ReverseDomainNameResolver.java @@ -104,23 +104,23 @@ public class ReverseDomainNameResolver { * lookups and some simple statistics on lookup time. */ public String getStatsString() { StringBuilder sb = new StringBuilder(); - sb.append(" " + FormattingUtils.formatDecimalNumber( - rdnsLookupMillis.size()) + " lookups performed\n"); - sb.append(" " + FormattingUtils.formatDecimalNumber( - rdnsVerifiedLookupResults.size()) + " verified results found\n"); - sb.append(" " + FormattingUtils.formatDecimalNumber( - rdnsUnverifiedLookupResults.size()) - + " unverified results found\n"); + sb.append(" ").append(FormattingUtils.formatDecimalNumber( + rdnsLookupMillis.size())).append(" lookups performed\n"); + sb.append(" ").append(FormattingUtils.formatDecimalNumber( + rdnsVerifiedLookupResults.size())).append(" verified results found\n"); + sb.append(" ").append(FormattingUtils.formatDecimalNumber( + rdnsUnverifiedLookupResults.size())) + .append(" unverified results found\n"); if (!rdnsLookupMillis.isEmpty()) { Collections.sort(rdnsLookupMillis); - sb.append(" " + FormattingUtils.formatMillis( - rdnsLookupMillis.get(0)) + " minimum lookup time\n"); - sb.append(" " + FormattingUtils.formatMillis( - rdnsLookupMillis.get(rdnsLookupMillis.size() / 2)) - + " median lookup time\n"); - sb.append(" " + FormattingUtils.formatMillis( - rdnsLookupMillis.get(rdnsLookupMillis.size() - 1)) - + " maximum lookup time\n"); + sb.append(" ").append(FormattingUtils.formatMillis( + rdnsLookupMillis.get(0))).append(" minimum lookup time\n"); + sb.append(" ").append(FormattingUtils.formatMillis( + rdnsLookupMillis.get(rdnsLookupMillis.size() / 2))) + .append(" median lookup time\n"); + sb.append(" ").append(FormattingUtils.formatMillis( + rdnsLookupMillis.get(rdnsLookupMillis.size() - 1))) + .append(" maximum lookup time\n"); } return sb.toString(); } diff --git a/src/main/java/org/torproject/onionoo/updater/UptimeStatusUpdater.java b/src/main/java/org/torproject/onionoo/updater/UptimeStatusUpdater.java index 338bf58..f1ff574 100644 --- a/src/main/java/org/torproject/onionoo/updater/UptimeStatusUpdater.java +++ b/src/main/java/org/torproject/onionoo/updater/UptimeStatusUpdater.java @@ -182,15 +182,15 @@ public class UptimeStatusUpdater implements DescriptorListener, @Override public String getStatsString() { StringBuilder sb = new StringBuilder(); - sb.append(" " + FormattingUtils.formatDecimalNumber( - this.newRelayStatuses.size()) + " hours of relay uptimes " - + "processed\n"); - sb.append(" " + FormattingUtils.formatDecimalNumber( - this.newBridgeStatuses.size()) + " hours of bridge uptimes " - + "processed\n"); - sb.append(" " + FormattingUtils.formatDecimalNumber( - this.newRunningRelays.size() + this.newRunningBridges.size()) - + " uptime status files updated\n"); + 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(); } } diff --git a/src/main/java/org/torproject/onionoo/writer/ClientsDocumentWriter.java b/src/main/java/org/torproject/onionoo/writer/ClientsDocumentWriter.java index de63893..2bf1862 100644 --- a/src/main/java/org/torproject/onionoo/writer/ClientsDocumentWriter.java +++ b/src/main/java/org/torproject/onionoo/writer/ClientsDocumentWriter.java @@ -120,8 +120,8 @@ public class ClientsDocumentWriter implements DocumentWriter { @Override public String getStatsString() { StringBuilder sb = new StringBuilder(); - sb.append(" " + FormattingUtils.formatDecimalNumber( - this.writtenDocuments) + " clients document files updated\n"); + sb.append(" ").append(FormattingUtils.formatDecimalNumber( + this.writtenDocuments)).append(" clients document files updated\n"); return sb.toString(); } } diff --git a/src/main/java/org/torproject/onionoo/writer/SummaryDocumentWriter.java b/src/main/java/org/torproject/onionoo/writer/SummaryDocumentWriter.java index 5063026..3fb8312 100644 --- a/src/main/java/org/torproject/onionoo/writer/SummaryDocumentWriter.java +++ b/src/main/java/org/torproject/onionoo/writer/SummaryDocumentWriter.java @@ -114,10 +114,10 @@ public class SummaryDocumentWriter implements DocumentWriter { @Override public String getStatsString() { StringBuilder sb = new StringBuilder(); - sb.append(" " + FormattingUtils.formatDecimalNumber( - this.writtenDocuments) + " summary document files written\n"); - sb.append(" " + FormattingUtils.formatDecimalNumber( - this.deletedDocuments) + " summary document files deleted\n"); + 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(); } } diff --git a/src/main/java/org/torproject/onionoo/writer/UptimeDocumentWriter.java b/src/main/java/org/torproject/onionoo/writer/UptimeDocumentWriter.java index 22b7ba5..73e8dee 100644 --- a/src/main/java/org/torproject/onionoo/writer/UptimeDocumentWriter.java +++ b/src/main/java/org/torproject/onionoo/writer/UptimeDocumentWriter.java @@ -239,8 +239,8 @@ public class UptimeDocumentWriter implements DocumentWriter { @Override public String getStatsString() { StringBuilder sb = new StringBuilder(); - sb.append(" " + FormattingUtils.formatDecimalNumber( - this.writtenDocuments) + " uptime document files written\n"); + sb.append(" ").append(FormattingUtils.formatDecimalNumber( + this.writtenDocuments)).append(" uptime document files written\n"); return sb.toString(); } }
tor-commits@lists.torproject.org