commit dfdc2c3b46f7ae615fce2709ec27f3a1f8153b63 Author: Karsten Loesing karsten.loesing@gmx.net Date: Thu Aug 31 22:33:29 2017 +0200
Make minor code improvements.
Improvements include: - Replace string concatenations with chained append() calls. - Apply diamond operator. - Switch to Double.compare() rather than re-implement that logic. - Added or removed arguments for printf() calls. - Remove unused constructors. - Remove unused imports. - Avoid NullPointerExceptions in edge cases. - Remove redundant initializations or assignments. - Remove unnecessary boxing of primitives. --- .../java/org/torproject/metrics/connbidirect/Main.java | 10 +++++----- .../org/torproject/metrics/connbidirect/MainTest.java | 15 +++++---------- .../org/torproject/metrics/hidserv/Aggregator.java | 9 ++++----- .../metrics/hidserv/ComputedNetworkFractions.java | 7 +------ .../org/torproject/metrics/hidserv/DocumentStore.java | 3 +-- .../metrics/hidserv/ExtrapolatedHidServStats.java | 8 +------- .../org/torproject/metrics/hidserv/Extrapolator.java | 3 +-- .../main/java/org/torproject/metrics/hidserv/Main.java | 2 -- .../java/org/torproject/metrics/hidserv/Parser.java | 2 +- .../metrics/hidserv/ReportedHidServStats.java | 8 +------- .../java/org/torproject/metrics/hidserv/Simulate.java | 4 ++-- .../main/java/org/torproject/ernie/cron/LockFile.java | 3 ++- .../src/main/java/org/torproject/ernie/cron/Main.java | 5 ++--- .../ernie/cron/RelayDescriptorDatabaseImporter.java | 7 +++---- .../ernie/cron/network/ConsensusStatsFileHandler.java | 9 ++++----- .../java/org/torproject/metrics/onionperf/Main.java | 1 - .../java/org/torproject/metrics/webstats/Main.java | 2 +- .../java/org/torproject/metrics/web/MetricServlet.java | 5 +---- .../java/org/torproject/metrics/web/NewsServlet.java | 16 ++++++++-------- .../metrics/web/graphs/GraphParameterChecker.java | 2 +- .../metrics/web/graphs/RObjectGenerator.java | 18 +++++++++--------- 21 files changed, 53 insertions(+), 86 deletions(-)
diff --git a/modules/connbidirect/src/main/java/org/torproject/metrics/connbidirect/Main.java b/modules/connbidirect/src/main/java/org/torproject/metrics/connbidirect/Main.java index 1de49d3..1624fa9 100644 --- a/modules/connbidirect/src/main/java/org/torproject/metrics/connbidirect/Main.java +++ b/modules/connbidirect/src/main/java/org/torproject/metrics/connbidirect/Main.java @@ -195,7 +195,7 @@ public class Main { BufferedReader br = new BufferedReader(new FileReader(file)); String line; while ((line = br.readLine()) != null) { - sb.append(line + "\n"); + sb.append(line).append("\n"); } br.close(); } @@ -221,7 +221,7 @@ public class Main { static String formatParseHistory(SortedMap<String, Long> parseHistory) { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, Long> e : parseHistory.entrySet()) { - sb.append(e.getKey() + "," + e.getValue() + "\n"); + sb.append(e.getKey()).append(",").append(e.getValue()).append("\n"); } return sb.toString(); } @@ -268,7 +268,7 @@ public class Main { StringBuilder sb = new StringBuilder(); sb.append(AGGREGATE_STATS_HEADER + "\n"); for (Map.Entry<String, Short> e : aggregateStats.entrySet()) { - sb.append(e.getKey() + "," + e.getValue() + "\n"); + sb.append(e.getKey()).append(",").append(e.getValue()).append("\n"); } return sb.toString(); } @@ -317,7 +317,7 @@ public class Main { static String formatRawStats(SortedSet<RawStat> rawStats) { StringBuilder sb = new StringBuilder(); for (RawStat rawStat : rawStats) { - sb.append(rawStat.toString() + "\n"); + sb.append(rawStat.toString()).append("\n"); } return sb.toString(); } @@ -442,7 +442,7 @@ public class Main { if (!fractionsByDateAndDirection.containsKey( dateAndDirection)) { fractionsByDateAndDirection.put(dateAndDirection, - new ArrayList<Short>()); + new ArrayList<>()); } fractionsByDateAndDirection.get(dateAndDirection).add( fractions[i]); diff --git a/modules/connbidirect/src/test/java/org/torproject/metrics/connbidirect/MainTest.java b/modules/connbidirect/src/test/java/org/torproject/metrics/connbidirect/MainTest.java index c63a772..c35fe80 100644 --- a/modules/connbidirect/src/test/java/org/torproject/metrics/connbidirect/MainTest.java +++ b/modules/connbidirect/src/test/java/org/torproject/metrics/connbidirect/MainTest.java @@ -29,8 +29,7 @@ public class MainTest {
@Test public void testParseHistoryEmpty() { - assertParseHistoryCanBeSerializedAndDeserialized( - new TreeMap<String, Long>()); + assertParseHistoryCanBeSerializedAndDeserialized(new TreeMap<>()); }
private final String pathA = "a"; @@ -89,8 +88,7 @@ public class MainTest {
@Test public void testAggregateStatsEmpty() { - assertAggregateStatsCanBeSerializedAndDeserialized( - new TreeMap<String, Short>()); + assertAggregateStatsCanBeSerializedAndDeserialized(new TreeMap<>()); }
@Test @@ -120,8 +118,7 @@ public class MainTest {
@Test public void testRawStatsEmpty() { - assertRawStatsCanBeSerializedAndDeserialized( - new TreeSet<Main.RawStat>()); + assertRawStatsCanBeSerializedAndDeserialized(new TreeSet<>()); }
private static final long DATE_A = 16665; /* 2015-08-18 */ @@ -155,8 +152,7 @@ public class MainTest { SortedSet<Main.RawStat> rawStats = new TreeSet<>(); rawStats.add(new Main.RawStat(DATE_A, FPR_A, (short) 40, (short) 30, (short) 50)); - assertRawStatsCanBeMerged(rawStats, new TreeSet<Main.RawStat>(), - false); + assertRawStatsCanBeMerged(rawStats, new TreeSet<>(), false); }
@Test @@ -222,8 +218,7 @@ public class MainTest {
@Test public void testUpdateAggregateStatsEmpty() { - assertStatsCanBeAggregated(new TreeMap<String, Short>(), - new TreeSet<Main.RawStat>()); + assertStatsCanBeAggregated(new TreeMap<>(), new TreeSet<>()); }
@Test diff --git a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Aggregator.java b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Aggregator.java index c438ea2..d7a1054 100644 --- a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Aggregator.java +++ b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Aggregator.java @@ -78,7 +78,7 @@ public class Aggregator { DateTimeHelper.ISO_DATE_FORMAT); if (extrapolated.getFractionRendRelayedCells() > 0.0) { if (!extrapolatedCells.containsKey(date)) { - extrapolatedCells.put(date, new ArrayList<double[]>()); + extrapolatedCells.put(date, new ArrayList<>()); } extrapolatedCells.get(date).add(new double[] { extrapolated.getExtrapolatedRendRelayedCells(), @@ -120,9 +120,7 @@ public class Aggregator { Collections.sort(weightedValues, new Comparator<double[]>() { public int compare(double[] first, double[] second) { - return first[0] < second[0] ? -1 - : first[0] > second[0] ? 1 - : 0; + return Double.compare(first[0], second[0]); } } ); @@ -189,7 +187,8 @@ public class Aggregator { this.hidservStatsCsvFile))) { bw.write(sb.toString()); } catch (IOException e) { - System.err.printf("Unable to write results to %s. Ignoring."); + System.err.printf("Unable to write results to %s. Ignoring.", + this.extrapolatedHidServStatsFile.getAbsolutePath()); } } } diff --git a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/ComputedNetworkFractions.java b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/ComputedNetworkFractions.java index a403e48..3ab90f3 100644 --- a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/ComputedNetworkFractions.java +++ b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/ComputedNetworkFractions.java @@ -116,11 +116,6 @@ public class ComputedNetworkFractions implements Document { return new String[] { first, second }; }
- /** Instantiates an empty fractions object that will be initialized more - * by the parse method. */ - ComputedNetworkFractions() { - } - private static Map<String, Long> previouslyParsedDates = Collections.synchronizedMap(new HashMap<String, Long>());
@@ -131,7 +126,7 @@ public class ComputedNetworkFractions implements Document { public boolean parse(String[] formattedStrings) { if (formattedStrings.length != 2) { System.err.printf("Invalid number of formatted strings. " - + "Skipping.%n", formattedStrings.length); + + "Skipping.%n"); return false; } String[] firstParts = formattedStrings[0].split(",", 2); diff --git a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/DocumentStore.java b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/DocumentStore.java index 5ecb849..6dde889 100644 --- a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/DocumentStore.java +++ b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/DocumentStore.java @@ -54,8 +54,7 @@ public class DocumentStore<T extends Document> { for (T retrieveDocument : retrievedDocuments) { String[] formattedDocument = retrieveDocument.format(); if (!formattedDocuments.containsKey(formattedDocument[0])) { - formattedDocuments.put(formattedDocument[0], - new TreeSet<String>()); + formattedDocuments.put(formattedDocument[0], new TreeSet<>()); } formattedDocuments.get(formattedDocument[0]).add( formattedDocument[1]); diff --git a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/ExtrapolatedHidServStats.java b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/ExtrapolatedHidServStats.java index 53bef71..d38174a 100644 --- a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/ExtrapolatedHidServStats.java +++ b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/ExtrapolatedHidServStats.java @@ -118,19 +118,13 @@ public class ExtrapolatedHidServStats implements Document { return new String[] { first, second }; }
- /** Instantiates an empty stats object that will be initialized more by - * the parse method. */ - ExtrapolatedHidServStats() { - } - /** Initializes this stats object using the two provided strings that * have been produced by the format method earlier and returns whether * this operation was successful. */ @Override public boolean parse(String[] formattedStrings) { if (formattedStrings.length != 2) { - System.err.printf("Invalid number of formatted strings. " - + "Skipping.%n", formattedStrings.length); + System.err.printf("Invalid number of formatted strings. Skipping.%n"); return false; } long statsDateMillis = DateTimeHelper.parse(formattedStrings[0], diff --git a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Extrapolator.java b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Extrapolator.java index 262720a..fdeafdf 100644 --- a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Extrapolator.java +++ b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Extrapolator.java @@ -95,8 +95,7 @@ public class Extrapolator { for (ReportedHidServStats stat : reportedStats) { String fingerprint = stat.getFingerprint(); if (!parsedStatsByFingerprint.containsKey(fingerprint)) { - parsedStatsByFingerprint.put(fingerprint, - new HashSet<ReportedHidServStats>()); + parsedStatsByFingerprint.put(fingerprint, new HashSet<>()); } parsedStatsByFingerprint.get(fingerprint).add(stat); } diff --git a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Main.java b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Main.java index 62a06b0..f027f1e 100644 --- a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Main.java +++ b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Main.java @@ -4,8 +4,6 @@ package org.torproject.metrics.hidserv;
import java.io.File; -import java.util.HashSet; -import java.util.Set;
/** Main class for updating extrapolated network totals of hidden-service * statistics. The main method of this class can be executed as often as diff --git a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Parser.java b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Parser.java index 3195dd8..b3f5361 100644 --- a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Parser.java +++ b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Parser.java @@ -268,7 +268,7 @@ public class Parser { /* More precisely, make sure that it contains Wmx weights, and then * parse them. */ SortedSet<String> expectedWeightKeys = - new TreeSet<String>(Arrays.asList("Wmg,Wmm,Wme,Wmd".split(","))); + new TreeSet<>(Arrays.asList("Wmg,Wmm,Wme,Wmd".split(","))); expectedWeightKeys.removeAll(bandwidthWeights.keySet()); if (!expectedWeightKeys.isEmpty()) { System.err.printf("Consensus with valid-after time %s doesn't " diff --git a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/ReportedHidServStats.java b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/ReportedHidServStats.java index 6d305d0..6f2d548 100644 --- a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/ReportedHidServStats.java +++ b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/ReportedHidServStats.java @@ -97,19 +97,13 @@ public class ReportedHidServStats implements Document { return new String[] { first, second }; }
- /* Instantiate an empty stats object that will be initialized more by - * the parse method. */ - ReportedHidServStats() { - } - /* Initialize this stats object using the two provided strings that have * been produced by the format method earlier. Return whether this * operation was successful. */ @Override public boolean parse(String[] formattedStrings) { if (formattedStrings.length != 2) { - System.err.printf("Invalid number of formatted strings. " - + "Skipping.%n", formattedStrings.length); + System.err.printf("Invalid number of formatted strings. Skipping.%n"); return false; } String[] secondParts = formattedStrings[1].split(",", 4); diff --git a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Simulate.java b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Simulate.java index 207b4aa..5419da9 100644 --- a/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Simulate.java +++ b/modules/hidserv/src/main/java/org/torproject/metrics/hidserv/Simulate.java @@ -238,7 +238,7 @@ public class Simulate { final int storeOnDirs = 3; SortedMap<Double, SortedSet<Integer>> storedDescs = new TreeMap<>(); for (double fingerprint : hsDirFingerprints) { - storedDescs.put(fingerprint, new TreeSet<Integer>()); + storedDescs.put(fingerprint, new TreeSet<>()); } for (int i = 0; i < numberOnions; i++) { for (int j = 0; j < replicas; j++) { @@ -334,7 +334,7 @@ public class Simulate { Collections.sort(singleRelayExtrapolations, new Comparator<double[]>() { public int compare(double[] first, double[] second) { - return first[0] < second[0] ? -1 : first[0] > second[0] ? 1 : 0; + return Double.compare(first[0], second[0]); } } ); diff --git a/modules/legacy/src/main/java/org/torproject/ernie/cron/LockFile.java b/modules/legacy/src/main/java/org/torproject/ernie/cron/LockFile.java index 48eb83d..862e1d2 100644 --- a/modules/legacy/src/main/java/org/torproject/ernie/cron/LockFile.java +++ b/modules/legacy/src/main/java/org/torproject/ernie/cron/LockFile.java @@ -37,7 +37,8 @@ public class LockFile { } } BufferedWriter bw = new BufferedWriter(new FileWriter("lock")); - bw.append("" + System.currentTimeMillis() + "\n"); + bw.append("").append(String.valueOf(System.currentTimeMillis())) + .append("\n"); bw.close(); this.logger.fine("Acquired lock."); return true; diff --git a/modules/legacy/src/main/java/org/torproject/ernie/cron/Main.java b/modules/legacy/src/main/java/org/torproject/ernie/cron/Main.java index 180031a..8b97143 100644 --- a/modules/legacy/src/main/java/org/torproject/ernie/cron/Main.java +++ b/modules/legacy/src/main/java/org/torproject/ernie/cron/Main.java @@ -50,10 +50,10 @@ public class Main { config.getDirectoryArchivesDirectories(), statsDirectory, config.getKeepDirectoryArchiveImportHistory()) : null; - if (rddi != null) { + if (null != rddi) { rddi.importRelayDescriptors(); + rddi.closeConnection(); } - rddi.closeConnection(); }
// Prepare consensus stats file handler (used for stats on running @@ -71,7 +71,6 @@ public class Main { csfh.importSanitizedBridges(); } csfh.writeFiles(); - csfh = null; }
// Remove lock file diff --git a/modules/legacy/src/main/java/org/torproject/ernie/cron/RelayDescriptorDatabaseImporter.java b/modules/legacy/src/main/java/org/torproject/ernie/cron/RelayDescriptorDatabaseImporter.java index a05c86c..856d2f7 100644 --- a/modules/legacy/src/main/java/org/torproject/ernie/cron/RelayDescriptorDatabaseImporter.java +++ b/modules/legacy/src/main/java/org/torproject/ernie/cron/RelayDescriptorDatabaseImporter.java @@ -30,7 +30,6 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -265,7 +264,7 @@ public final class RelayDescriptorDatabaseImporter { if (!this.importIntoDatabase) { return; } - long dateMillis = 0L; + long dateMillis; try { dateMillis = this.dateTimeFormat.parse( this.dateTimeFormat.format(timestamp).substring(0, 10) @@ -500,7 +499,7 @@ public final class RelayDescriptorDatabaseImporter { StringBuilder sb = new StringBuilder("[" + offset + ":" + (offset + array.length - 1) + "]={"); for (int i = 0; i < array.length; i++) { - sb.append((i > 0 ? "," : "") + array[i]); + sb.append(i > 0 ? "," : "").append(array[i]); } sb.append('}'); this.stringValue = sb.toString(); @@ -573,7 +572,7 @@ public final class RelayDescriptorDatabaseImporter { + "number of elements. Ignoring this line."); continue; } - long intervalLength = 0L; + long intervalLength; try { intervalLength = Long.parseLong(parts[3].substring(1)); } catch (NumberFormatException e) { diff --git a/modules/legacy/src/main/java/org/torproject/ernie/cron/network/ConsensusStatsFileHandler.java b/modules/legacy/src/main/java/org/torproject/ernie/cron/network/ConsensusStatsFileHandler.java index fd77fa9..c4b8770 100644 --- a/modules/legacy/src/main/java/org/torproject/ernie/cron/network/ConsensusStatsFileHandler.java +++ b/modules/legacy/src/main/java/org/torproject/ernie/cron/network/ConsensusStatsFileHandler.java @@ -24,7 +24,6 @@ import java.sql.Statement; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import java.util.SortedMap; import java.util.TimeZone; @@ -124,7 +123,7 @@ public class ConsensusStatsFileHandler { + this.bridgeConsensusStatsRawFile.getAbsolutePath() + "..."); try (BufferedReader br = new BufferedReader(new FileReader( this.bridgeConsensusStatsRawFile))) { - String line = null; + String line; while ((line = br.readLine()) != null) { if (line.startsWith("date")) { /* Skip headers. */ @@ -256,7 +255,7 @@ public class ConsensusStatsFileHandler { } String date = bridgesRawLine.substring(0, 10); if (!bridgesPerDayAndAuthority.containsKey(date)) { - bridgesPerDayAndAuthority.put(date, new TreeMap<String, int[]>()); + bridgesPerDayAndAuthority.put(date, new TreeMap<>()); } String authority = parts[1]; if (!bridgesPerDayAndAuthority.get(date).containsKey(authority)) { @@ -392,8 +391,8 @@ public class ConsensusStatsFileHandler { if (this.bridgesRaw.isEmpty()) { dumpStats.append("\nNo bridge status known yet."); } else { - dumpStats.append("\nLast known bridge status was published " - + this.bridgesRaw.lastKey() + "."); + dumpStats.append("\nLast known bridge status was published ") + .append(this.bridgesRaw.lastKey()).append("."); try { if (now - 6L * 60L * 60L * 1000L > dateTimeFormat.parse( this.bridgesRaw.lastKey()).getTime()) { diff --git a/modules/onionperf/src/main/java/org/torproject/metrics/onionperf/Main.java b/modules/onionperf/src/main/java/org/torproject/metrics/onionperf/Main.java index 23cc424..04c5dd5 100644 --- a/modules/onionperf/src/main/java/org/torproject/metrics/onionperf/Main.java +++ b/modules/onionperf/src/main/java/org/torproject/metrics/onionperf/Main.java @@ -26,7 +26,6 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.SortedSet; diff --git a/modules/webstats/src/main/java/org/torproject/metrics/webstats/Main.java b/modules/webstats/src/main/java/org/torproject/metrics/webstats/Main.java index 7ba08d7..1b4072a 100644 --- a/modules/webstats/src/main/java/org/torproject/metrics/webstats/Main.java +++ b/modules/webstats/src/main/java/org/torproject/metrics/webstats/Main.java @@ -208,7 +208,7 @@ public class Main { String site = logFileUrlMatcher.group(2); long logDateMillis = logDateFormat.parse(logFileUrlMatcher.group(3)) .getTime(); - return new Object[] { server, site, new Long(logDateMillis) }; + return new Object[] { server, site, logDateMillis }; }
static Map<String, Integer> downloadAndParseLogFile(String urlString) diff --git a/website/src/main/java/org/torproject/metrics/web/MetricServlet.java b/website/src/main/java/org/torproject/metrics/web/MetricServlet.java index 02dcd53..730a767 100644 --- a/website/src/main/java/org/torproject/metrics/web/MetricServlet.java +++ b/website/src/main/java/org/torproject/metrics/web/MetricServlet.java @@ -3,7 +3,6 @@
package org.torproject.metrics.web;
-import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -38,14 +37,12 @@ public abstract class MetricServlet extends AnyServlet { public void init() throws ServletException { super.init(); this.metrics = ContentProvider.getInstance().getMetricsList(); - Map<String, String> allTypesAndTitles = new HashMap<>(); for (Metric metric : this.metrics) { String id = metric.getId(); String title = metric.getTitle(); String type = metric.getType(); - allTypesAndTitles.put(id, String.format("%s: %s", type, title)); if (!this.idsByType.containsKey(type)) { - this.idsByType.put(type, new HashSet<String>()); + this.idsByType.put(type, new HashSet<>()); } this.idsByType.get(type).add(id); this.titles.put(id, title); diff --git a/website/src/main/java/org/torproject/metrics/web/NewsServlet.java b/website/src/main/java/org/torproject/metrics/web/NewsServlet.java index 1dfea4c..2e9bdb1 100644 --- a/website/src/main/java/org/torproject/metrics/web/NewsServlet.java +++ b/website/src/main/java/org/torproject/metrics/web/NewsServlet.java @@ -84,18 +84,18 @@ public class NewsServlet extends AnyServlet { /* Sort news into categories. */ Map<String[], List<String[]>> newsByCategory = new LinkedHashMap<>(); for (String[] category : cutOffDates.values()) { - newsByCategory.put(category, new ArrayList<String[]>()); + newsByCategory.put(category, new ArrayList<>()); } for (News news : this.sortedNews) { StringBuilder sb = new StringBuilder(); - sb.append("<h3 class="media-heading">" + news.getStart()); + sb.append("<h3 class="media-heading">").append(news.getStart()); if (news.getEnd() != null) { - sb.append(" to " + news.getEnd()); + sb.append(" to ").append(news.getEnd()); } if (news.getPlace() != null) { if (this.countries.containsKey(news.getPlace())) { - sb.append(" <span class="label label-warning">" - + this.countries.get(news.getPlace()) + "</span>"); + sb.append(" <span class="label label-warning">") + .append(this.countries.get(news.getPlace())).append("</span>"); } else { sb.append(" <span class="label label-warning">" + "Unknown country</span>"); @@ -117,8 +117,8 @@ public class NewsServlet extends AnyServlet { + "<OR></span>"); break; default: - sb.append(" <span class="label label-info">" - + protocol + "</span>"); + sb.append(" <span class="label label-info">").append(protocol) + .append("</span>"); break; } } @@ -127,7 +127,7 @@ public class NewsServlet extends AnyServlet { sb.append(" <span class="label label-default">" + "Unknown</span>"); } - sb.append("</h3><p>" + news.getDescription() + "</p>"); + sb.append("</h3><p>").append(news.getDescription()).append("</p>"); if (news.getLinks() != null && news.getLinks().length > 0) { int written = 0; sb.append("<p class="links">"); diff --git a/website/src/main/java/org/torproject/metrics/web/graphs/GraphParameterChecker.java b/website/src/main/java/org/torproject/metrics/web/graphs/GraphParameterChecker.java index c693706..e08a5bf 100644 --- a/website/src/main/java/org/torproject/metrics/web/graphs/GraphParameterChecker.java +++ b/website/src/main/java/org/torproject/metrics/web/graphs/GraphParameterChecker.java @@ -60,7 +60,7 @@ public class GraphParameterChecker { "Running,Exit,Guard,Fast,Stable,HSDir"); StringBuilder sb = new StringBuilder("all"); for (String[] country : Countries.getInstance().getCountryList()) { - sb.append("," + country[0]); + sb.append(",").append(country[0]); } this.knownParameterValues.put("country", sb.toString()); this.knownParameterValues.put("events", "on,off,points"); diff --git a/website/src/main/java/org/torproject/metrics/web/graphs/RObjectGenerator.java b/website/src/main/java/org/torproject/metrics/web/graphs/RObjectGenerator.java index 719a5c4..7477303 100644 --- a/website/src/main/java/org/torproject/metrics/web/graphs/RObjectGenerator.java +++ b/website/src/main/java/org/torproject/metrics/web/graphs/RObjectGenerator.java @@ -135,21 +135,21 @@ public class RObjectGenerator implements ServletContextListener { String parameterName = parameter.getKey(); String[] parameterValues = parameter.getValue(); for (String param : parameterValues) { - imageFilenameBuilder.append("-" + param); + imageFilenameBuilder.append("-").append(param); } if (parameterValues.length < 2) { - queryBuilder.append(parameterName + " = '" + parameterValues[0] - + "', "); + queryBuilder.append(parameterName).append(" = '") + .append(parameterValues[0]).append("', "); } else { - queryBuilder.append(parameterName + " = c("); + queryBuilder.append(parameterName).append(" = c("); for (int i = 0; i < parameterValues.length - 1; i++) { - queryBuilder.append("'" + parameterValues[i] + "', "); + queryBuilder.append("'").append(parameterValues[i]).append("', "); } - queryBuilder.append("'" + parameterValues[ - parameterValues.length - 1] + "'), "); + queryBuilder.append("'").append(parameterValues[ + parameterValues.length - 1]).append("'), "); } } - imageFilenameBuilder.append("." + fileType); + imageFilenameBuilder.append(".").append(fileType); String imageFilename = imageFilenameBuilder.toString(); queryBuilder.append("path = '%s')"); String query = queryBuilder.toString(); @@ -249,7 +249,7 @@ public class RObjectGenerator implements ServletContextListener { * already running worker thread to finish and get its result. */ private RObject generateObject(String query, File objectFile, String fileName, boolean checkCache) { - RObjectGeneratorWorker worker = null; + RObjectGeneratorWorker worker; synchronized (this.objectGeneratorThreads) { if (this.objectGeneratorThreads.containsKey(query)) { worker = this.objectGeneratorThreads.get(query);
tor-commits@lists.torproject.org