commit 7456617d5b6bbb52ad854deeb06308b5129e9812 Author: iwakeh iwakeh@torproject.org Date: Wed Dec 20 13:06:52 2017 +0000
Rename 'getColumnHeaders' to reflect that it is no getter.
And use some java 8 to shorten the method. --- .../org/torproject/metrics/stats/ipv6servers/Database.java | 2 +- .../torproject/metrics/stats/ipv6servers/OutputLine.java | 13 +++++-------- .../org/torproject/metrics/stats/ipv6servers/Writer.java | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/torproject/metrics/stats/ipv6servers/Database.java b/src/main/java/org/torproject/metrics/stats/ipv6servers/Database.java index 401bdb7..e95aba0 100644 --- a/src/main/java/org/torproject/metrics/stats/ipv6servers/Database.java +++ b/src/main/java/org/torproject/metrics/stats/ipv6servers/Database.java @@ -181,7 +181,7 @@ class Database implements AutoCloseable { Statement st = this.connection.createStatement(); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.US); - String queryString = "SELECT " + OutputLine.getColumnHeaders(", ") + String queryString = "SELECT " + OutputLine.columnHeadersDelimitedBy(", ") + " FROM ipv6servers"; try (ResultSet rs = st.executeQuery(queryString)) { while (rs.next()) { diff --git a/src/main/java/org/torproject/metrics/stats/ipv6servers/OutputLine.java b/src/main/java/org/torproject/metrics/stats/ipv6servers/OutputLine.java index eba5f13..31838d3 100644 --- a/src/main/java/org/torproject/metrics/stats/ipv6servers/OutputLine.java +++ b/src/main/java/org/torproject/metrics/stats/ipv6servers/OutputLine.java @@ -4,8 +4,8 @@ package org.torproject.metrics.stats.ipv6servers;
import java.time.LocalDate; -import java.util.ArrayList; -import java.util.List; +import java.util.Arrays; +import java.util.stream.Collectors;
/** Data object holding all parts of an output line. */ class OutputLine { @@ -19,12 +19,9 @@ class OutputLine { }
/** Column headers joined together with the given delimiter. */ - static String getColumnHeaders(String delimiter) { - List<String> columnHeaders = new ArrayList<>(); - for (Column column : Column.values()) { - columnHeaders.add(column.toString()); - } - return String.join(delimiter, columnHeaders).toLowerCase(); + static String columnHeadersDelimitedBy(String delimiter) { + return Arrays.stream(Column.values()).map(c -> c.toString()) + .collect(Collectors.joining(delimiter)); }
/** Date. */ diff --git a/src/main/java/org/torproject/metrics/stats/ipv6servers/Writer.java b/src/main/java/org/torproject/metrics/stats/ipv6servers/Writer.java index 13c621f..388fb4d 100644 --- a/src/main/java/org/torproject/metrics/stats/ipv6servers/Writer.java +++ b/src/main/java/org/torproject/metrics/stats/ipv6servers/Writer.java @@ -26,7 +26,7 @@ class Writer { } } List<String> formattedOutputLines = new ArrayList<>(); - formattedOutputLines.add(OutputLine.getColumnHeaders(",")); + formattedOutputLines.add(OutputLine.columnHeadersDelimitedBy(",")); for (OutputLine line : outputLines) { formattedOutputLines.add(line.toString()); }
tor-commits@lists.torproject.org