From 6d5611f7939f342cd35c1df42c063601a993750d Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Mon, 10 Aug 2015 21:08:58 +0000 Subject: [PATCH] Use final. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1695167 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/csv/CSVParser.java | 4 +- .../org/apache/commons/csv/CSVPrinter.java | 2 +- .../org/apache/commons/csv/CSVRecord.java | 2 +- .../org/apache/commons/csv/CSVBenchmark.java | 56 +++++++++---------- .../org/apache/commons/csv/CSVParserTest.java | 4 +- .../apache/commons/csv/CSVPrinterTest.java | 2 +- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index 66216283..220ae92b 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -273,7 +273,7 @@ public final class CSVParser implements Iterable, Closeable { * If there is a problem reading the header or skipping the first record * @since 1.1 */ - public CSVParser(final Reader reader, final CSVFormat format, long characterOffset, long recordNumber) + public CSVParser(final Reader reader, final CSVFormat format, final long characterOffset, final long recordNumber) throws IOException { Assertions.notNull(reader, "reader"); Assertions.notNull(format, "format"); @@ -361,7 +361,7 @@ public final class CSVParser implements Iterable, Closeable { */ public List getRecords() throws IOException { CSVRecord rec; - List records = new ArrayList(); + final List records = new ArrayList(); while ((rec = this.nextRecord()) != null) { records.add(rec); } diff --git a/src/main/java/org/apache/commons/csv/CSVPrinter.java b/src/main/java/org/apache/commons/csv/CSVPrinter.java index f220c541..99952975 100644 --- a/src/main/java/org/apache/commons/csv/CSVPrinter.java +++ b/src/main/java/org/apache/commons/csv/CSVPrinter.java @@ -67,7 +67,7 @@ public final class CSVPrinter implements Flushable, Closeable { // TODO: Is it a good idea to do this here instead of on the first call to a print method? // It seems a pain to have to track whether the header has already been printed or not. if (format.getHeaderComments() != null) { - for (String line : format.getHeaderComments()) { + for (final String line : format.getHeaderComments()) { if (line != null) { this.printComment(line); } diff --git a/src/main/java/org/apache/commons/csv/CSVRecord.java b/src/main/java/org/apache/commons/csv/CSVRecord.java index 0c940858..5567f5ec 100644 --- a/src/main/java/org/apache/commons/csv/CSVRecord.java +++ b/src/main/java/org/apache/commons/csv/CSVRecord.java @@ -51,7 +51,7 @@ public final class CSVRecord implements Serializable, Iterable { private final String[] values; CSVRecord(final String[] values, final Map mapping, final String comment, final long recordNumber, - long characterPosition) { + final long characterPosition) { this.recordNumber = recordNumber; this.values = values != null ? values : EMPTY_STRING_ARRAY; this.mapping = mapping; diff --git a/src/test/java/org/apache/commons/csv/CSVBenchmark.java b/src/test/java/org/apache/commons/csv/CSVBenchmark.java index c0272981..b2ecd528 100644 --- a/src/test/java/org/apache/commons/csv/CSVBenchmark.java +++ b/src/test/java/org/apache/commons/csv/CSVBenchmark.java @@ -61,8 +61,8 @@ public class CSVBenchmark { */ @Setup public void init() throws IOException { - File file = new File("src/test/resources/perf/worldcitiespop.txt.gz"); - InputStream in = new GZIPInputStream(new FileInputStream(file)); + 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"); in.close(); } @@ -72,8 +72,8 @@ public class CSVBenchmark { } @Benchmark - public int read(Blackhole bh) throws Exception { - BufferedReader in = getReader(); + public int read(final Blackhole bh) throws Exception { + final BufferedReader in = getReader(); int count = 0; String line; while ((line = in.readLine()) != null) { @@ -86,12 +86,12 @@ public class CSVBenchmark { } @Benchmark - public int split(Blackhole bh) throws Exception { - BufferedReader in = getReader(); + public int split(final Blackhole bh) throws Exception { + final BufferedReader in = getReader(); int count = 0; String line; while ((line = in.readLine()) != null) { - String[] values = StringUtils.split(line, ','); + final String[] values = StringUtils.split(line, ','); count += values.length; } @@ -101,13 +101,13 @@ public class CSVBenchmark { } @Benchmark - public int parseCommonsCSV(Blackhole bh) throws Exception { - BufferedReader in = getReader(); + public int parseCommonsCSV(final Blackhole bh) throws Exception { + final BufferedReader in = getReader(); - CSVFormat format = CSVFormat.DEFAULT.withHeader(); + final CSVFormat format = CSVFormat.DEFAULT.withHeader(); int count = 0; - for (CSVRecord record : format.parse(in)) { + for (final CSVRecord record : format.parse(in)) { count++; } @@ -117,10 +117,10 @@ public class CSVBenchmark { } @Benchmark - public int parseGenJavaCSV(Blackhole bh) throws Exception { - BufferedReader in = getReader(); + public int parseGenJavaCSV(final Blackhole bh) throws Exception { + final BufferedReader in = getReader(); - CsvReader reader = new CsvReader(in); + final CsvReader reader = new CsvReader(in); reader.setFieldDelimiter(','); int count = 0; @@ -135,10 +135,10 @@ public class CSVBenchmark { } @Benchmark - public int parseJavaCSV(Blackhole bh) throws Exception { - BufferedReader in = getReader(); + public int parseJavaCSV(final Blackhole bh) throws Exception { + final BufferedReader in = getReader(); - com.csvreader.CsvReader reader = new com.csvreader.CsvReader(in, ','); + final com.csvreader.CsvReader reader = new com.csvreader.CsvReader(in, ','); reader.setRecordDelimiter('\n'); int count = 0; @@ -152,10 +152,10 @@ public class CSVBenchmark { } @Benchmark - public int parseOpenCSV(Blackhole bh) throws Exception { - BufferedReader in = getReader(); + public int parseOpenCSV(final Blackhole bh) throws Exception { + final BufferedReader in = getReader(); - com.opencsv.CSVReader reader = new com.opencsv.CSVReader(in, ','); + final com.opencsv.CSVReader reader = new com.opencsv.CSVReader(in, ','); int count = 0; while (reader.readNext() != null) { @@ -168,13 +168,13 @@ public class CSVBenchmark { } @Benchmark - public int parseSkifeCSV(Blackhole bh) throws Exception { - BufferedReader in = getReader(); + public int parseSkifeCSV(final Blackhole bh) throws Exception { + final BufferedReader in = getReader(); - org.skife.csv.CSVReader reader = new org.skife.csv.SimpleReader(); + final org.skife.csv.CSVReader reader = new org.skife.csv.SimpleReader(); reader.setSeperator(','); - CountingReaderCallback callback = new CountingReaderCallback(); + final CountingReaderCallback callback = new CountingReaderCallback(); reader.parse(in, callback); bh.consume(callback); @@ -186,16 +186,16 @@ public class CSVBenchmark { public int count = 0; @Override - public void onRow(String[] fields) { + public void onRow(final String[] fields) { count++; } } @Benchmark - public int parseSuperCSV(Blackhole bh) throws Exception { - BufferedReader in = getReader(); + public int parseSuperCSV(final Blackhole bh) throws Exception { + final BufferedReader in = getReader(); - CsvListReader reader = new CsvListReader(in, CsvPreference.STANDARD_PREFERENCE); + final CsvListReader reader = new CsvListReader(in, CsvPreference.STANDARD_PREFERENCE); int count = 0; List record = null; diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index e8825a2e..fc8b5d66 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -395,7 +395,7 @@ public class CSVParserTest { final String code = "A,B,C,,\r\na,b,c,d,e\r\n"; final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL.withHeader()); try { - for (CSVRecord record : parser.getRecords()) { + for (final CSVRecord record : parser.getRecords()) { Assert.assertEquals("a", record.get("A")); Assert.assertEquals("b", record.get("B")); Assert.assertEquals("c", record.get("C")); @@ -917,7 +917,7 @@ public class CSVParserTest { private void validateRecordPosition(final String lineSeparator) throws IOException { final String nl = lineSeparator; // used as linebreak in values for better distinction - String code = "a,b,c" + lineSeparator + "1,2,3" + lineSeparator + + final String code = "a,b,c" + lineSeparator + "1,2,3" + lineSeparator + // to see if recordPosition correctly points to the enclosing quote "'A" + nl + "A','B" + nl + "B',CC" + lineSeparator + // unicode test... not very relevant while operating on strings instead of bytes, but for diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java index 2d5750a5..3265b848 100644 --- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java +++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java @@ -281,7 +281,7 @@ public class CSVPrinterTest { } private void setUpTable(final Connection connection) throws SQLException { - Statement statement = connection.createStatement(); + final Statement statement = connection.createStatement(); try { statement.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"); statement.execute("insert into TEST values(1, 'r1')");