Commit c4145430 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Use chained String.append calls.

parent cc0ed7b0
......@@ -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();
}
......
......@@ -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()));
}
}
......
......@@ -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();
}
......
......@@ -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();
}
}
......
......@@ -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();
......
......@@ -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();
}
......
......@@ -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()) {
......
......@@ -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();
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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();
}
}
......
......@@ -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();
}
}
......
......@@ -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();
}
}
......
......@@ -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();
}
......
......@@ -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();
}
}
......
......@@ -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();
}
}
......
......@@ -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();
}
}
......
......@@ -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();
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment