This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git
The following commit(s) were added to refs/heads/master by this push:
new d580c90 Minor Improvement: (#127)
d580c90 is described below
commit d580c90f73e17aca94204d03c7a472807205997d
Author: Arturo Bernal <[email protected]>
AuthorDate: Wed Dec 30 15:52:52 2020 +0100
Minor Improvement: (#127)
* Add final
* Unnecessary semicolon ''
* Use StandardCharsets
* Fix javadoc
---
src/main/java/org/apache/commons/csv/CSVFormat.java | 12 ++++++------
src/test/java/org/apache/commons/csv/CSVBenchmark.java | 3 ++-
src/test/java/org/apache/commons/csv/CSVFileParserTest.java | 3 ++-
src/test/java/org/apache/commons/csv/CSVParserTest.java | 2 +-
src/test/java/org/apache/commons/csv/CSVPrinterTest.java | 2 +-
src/test/java/org/apache/commons/csv/PerformanceTest.java | 6 +++---
6 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java
b/src/main/java/org/apache/commons/csv/CSVFormat.java
index cd621bb..9cfd6b8 100644
--- a/src/main/java/org/apache/commons/csv/CSVFormat.java
+++ b/src/main/java/org/apache/commons/csv/CSVFormat.java
@@ -1402,7 +1402,6 @@ public final class CSVFormat implements Serializable {
int start = 0;
int pos = 0;
final int len = value.length();
- final int end = len;
final char delimChar = getDelimiter();
final char quoteChar = getQuoteCharacter().charValue();
@@ -1445,7 +1444,7 @@ public final class CSVFormat implements Serializable {
// by including the default comment char too.
quote = true;
} else {
- while (pos < end) {
+ while (pos < len) {
c = value.charAt(pos);
if (c == LF || c == CR || c == quoteChar || c ==
delimChar || c == escapeChar) {
quote = true;
@@ -1455,7 +1454,7 @@ public final class CSVFormat implements Serializable {
}
if (!quote) {
- pos = end - 1;
+ pos = len - 1;
c = value.charAt(pos);
// Some other chars at the end caused the parser to
fail, so for now
// encapsulate if we end in anything less than ' '
@@ -1468,7 +1467,7 @@ public final class CSVFormat implements Serializable {
if (!quote) {
// no encapsulation needed - write out the original value
- out.append(value, start, end);
+ out.append(value, start, len);
return;
}
break;
@@ -1478,7 +1477,7 @@ public final class CSVFormat implements Serializable {
if (!quote) {
// no encapsulation needed - write out the original value
- out.append(value, start, end);
+ out.append(value, start, len);
return;
}
@@ -1487,7 +1486,7 @@ public final class CSVFormat implements Serializable {
// Pick up where we left off: pos should be positioned on the first
character that caused
// the need for encapsulation.
- while (pos < end) {
+ while (pos < len) {
final char c = value.charAt(pos);
if (c == quoteChar || c == escapeChar) {
// write out the chunk up until this point
@@ -1507,6 +1506,7 @@ public final class CSVFormat implements Serializable {
* Always use quotes unless QuoteMode is NONE, so we not have to look
ahead.
*
* @throws IOException
+ * If an I/O error occurs
*/
private void printWithQuotes(final Reader reader, final Appendable out)
throws IOException {
diff --git a/src/test/java/org/apache/commons/csv/CSVBenchmark.java
b/src/test/java/org/apache/commons/csv/CSVBenchmark.java
index 6d951ba..e061dd2 100644
--- a/src/test/java/org/apache/commons/csv/CSVBenchmark.java
+++ b/src/test/java/org/apache/commons/csv/CSVBenchmark.java
@@ -23,6 +23,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;
@@ -63,7 +64,7 @@ public class CSVBenchmark {
public void init() throws IOException {
final File file = new
File("src/test/resources/perf/worldcitiespop.txt.gz");
final InputStream in = new GZIPInputStream(new FileInputStream(file));
- this.data = IOUtils.toString(in, "ISO-8859-1");
+ this.data = IOUtils.toString(in, StandardCharsets.ISO_8859_1);
in.close();
}
diff --git a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
index d71007b..61a6ebd 100644
--- a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
@@ -29,6 +29,7 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.stream.Stream;
@@ -135,7 +136,7 @@ public class CSVFileParserTest {
// Now parse the file and compare against the expected results
final URL resource =
ClassLoader.getSystemResource("org/apache/commons/csv/CSVFileParser/" +
split[0]);
- try (final CSVParser parser = CSVParser.parse(resource,
Charset.forName("UTF-8"), format)) {
+ try (final CSVParser parser = CSVParser.parse(resource,
StandardCharsets.UTF_8, format)) {
for (final CSVRecord record : parser) {
String parsed = Arrays.toString(record.values());
final String comment = record.getComment();
diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java
b/src/test/java/org/apache/commons/csv/CSVParserTest.java
index 0df4f0e..14e62a3 100644
--- a/src/test/java/org/apache/commons/csv/CSVParserTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java
@@ -572,7 +572,7 @@ public class CSVParserTest {
/**
* Tests reusing a parser to process new string records one at a time as
they are being discovered. See [CSV-110].
*
- * @throws IOException
+ * @throws IOException when an I/O error occurs.
*/
@Test
public void testGetOneLineOneParser() throws IOException {
diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
index 66033b4..39e83b0 100644
--- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
@@ -635,7 +635,7 @@ public class CSVPrinterTest {
public void testJdbcPrinterWithResultSet() throws IOException,
ClassNotFoundException, SQLException {
final StringWriter sw = new StringWriter();
Class.forName("org.h2.Driver");
- try (final Connection connection = geH2Connection();) {
+ try (final Connection connection = geH2Connection()) {
setUpTable(connection);
try (final Statement stmt = connection.createStatement();
final ResultSet resultSet = stmt.executeQuery("select ID,
NAME, TEXT from TEST");
diff --git a/src/test/java/org/apache/commons/csv/PerformanceTest.java
b/src/test/java/org/apache/commons/csv/PerformanceTest.java
index 023f2f5..10381a6 100644
--- a/src/test/java/org/apache/commons/csv/PerformanceTest.java
+++ b/src/test/java/org/apache/commons/csv/PerformanceTest.java
@@ -64,7 +64,7 @@ public class PerformanceTest {
private static int max = 11; // skip first test
private static int num = 0; // number of elapsed times recorded
- private static long[] elapsedTimes = new long[max];
+ private static final long[] ELAPSED_TIMES = new long[max];
private static final CSVFormat format = CSVFormat.EXCEL;
@@ -149,7 +149,7 @@ public class PerformanceTest {
private static void show(final String msg, final Stats s, final long
start) {
final long elapsed = System.currentTimeMillis() - start;
System.out.printf("%-20s: %5dms %d lines %d fields%n", msg, elapsed,
s.count, s.fields);
- elapsedTimes[num] = elapsed;
+ ELAPSED_TIMES[num] = elapsed;
num++;
}
@@ -158,7 +158,7 @@ public class PerformanceTest {
if (num > 1) {
long tot = 0;
for (int i = 1; i < num; i++) { // skip first test
- tot += elapsedTimes[i];
+ tot += ELAPSED_TIMES[i];
}
System.out.printf("%-20s: %5dms%n%n", "Average(not first)", tot /
(num - 1));
}