Use final.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1695167 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2015-08-10 21:08:58 +00:00
parent 0e91beab00
commit 6d5611f793
6 changed files with 35 additions and 35 deletions

View File

@ -273,7 +273,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
* If there is a problem reading the header or skipping the first record * If there is a problem reading the header or skipping the first record
* @since 1.1 * @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 { throws IOException {
Assertions.notNull(reader, "reader"); Assertions.notNull(reader, "reader");
Assertions.notNull(format, "format"); Assertions.notNull(format, "format");
@ -361,7 +361,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
*/ */
public List<CSVRecord> getRecords() throws IOException { public List<CSVRecord> getRecords() throws IOException {
CSVRecord rec; CSVRecord rec;
List<CSVRecord> records = new ArrayList<CSVRecord>(); final List<CSVRecord> records = new ArrayList<CSVRecord>();
while ((rec = this.nextRecord()) != null) { while ((rec = this.nextRecord()) != null) {
records.add(rec); records.add(rec);
} }

View File

@ -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? // 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. // It seems a pain to have to track whether the header has already been printed or not.
if (format.getHeaderComments() != null) { if (format.getHeaderComments() != null) {
for (String line : format.getHeaderComments()) { for (final String line : format.getHeaderComments()) {
if (line != null) { if (line != null) {
this.printComment(line); this.printComment(line);
} }

View File

@ -51,7 +51,7 @@ public final class CSVRecord implements Serializable, Iterable<String> {
private final String[] values; private final String[] values;
CSVRecord(final String[] values, final Map<String, Integer> mapping, final String comment, final long recordNumber, CSVRecord(final String[] values, final Map<String, Integer> mapping, final String comment, final long recordNumber,
long characterPosition) { final long characterPosition) {
this.recordNumber = recordNumber; this.recordNumber = recordNumber;
this.values = values != null ? values : EMPTY_STRING_ARRAY; this.values = values != null ? values : EMPTY_STRING_ARRAY;
this.mapping = mapping; this.mapping = mapping;

View File

@ -61,8 +61,8 @@ public class CSVBenchmark {
*/ */
@Setup @Setup
public void init() throws IOException { public void init() throws IOException {
File file = new File("src/test/resources/perf/worldcitiespop.txt.gz"); final File file = new File("src/test/resources/perf/worldcitiespop.txt.gz");
InputStream in = new GZIPInputStream(new FileInputStream(file)); final InputStream in = new GZIPInputStream(new FileInputStream(file));
this.data = IOUtils.toString(in, "ISO-8859-1"); this.data = IOUtils.toString(in, "ISO-8859-1");
in.close(); in.close();
} }
@ -72,8 +72,8 @@ public class CSVBenchmark {
} }
@Benchmark @Benchmark
public int read(Blackhole bh) throws Exception { public int read(final Blackhole bh) throws Exception {
BufferedReader in = getReader(); final BufferedReader in = getReader();
int count = 0; int count = 0;
String line; String line;
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
@ -86,12 +86,12 @@ public class CSVBenchmark {
} }
@Benchmark @Benchmark
public int split(Blackhole bh) throws Exception { public int split(final Blackhole bh) throws Exception {
BufferedReader in = getReader(); final BufferedReader in = getReader();
int count = 0; int count = 0;
String line; String line;
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
String[] values = StringUtils.split(line, ','); final String[] values = StringUtils.split(line, ',');
count += values.length; count += values.length;
} }
@ -101,13 +101,13 @@ public class CSVBenchmark {
} }
@Benchmark @Benchmark
public int parseCommonsCSV(Blackhole bh) throws Exception { public int parseCommonsCSV(final Blackhole bh) throws Exception {
BufferedReader in = getReader(); final BufferedReader in = getReader();
CSVFormat format = CSVFormat.DEFAULT.withHeader(); final CSVFormat format = CSVFormat.DEFAULT.withHeader();
int count = 0; int count = 0;
for (CSVRecord record : format.parse(in)) { for (final CSVRecord record : format.parse(in)) {
count++; count++;
} }
@ -117,10 +117,10 @@ public class CSVBenchmark {
} }
@Benchmark @Benchmark
public int parseGenJavaCSV(Blackhole bh) throws Exception { public int parseGenJavaCSV(final Blackhole bh) throws Exception {
BufferedReader in = getReader(); final BufferedReader in = getReader();
CsvReader reader = new CsvReader(in); final CsvReader reader = new CsvReader(in);
reader.setFieldDelimiter(','); reader.setFieldDelimiter(',');
int count = 0; int count = 0;
@ -135,10 +135,10 @@ public class CSVBenchmark {
} }
@Benchmark @Benchmark
public int parseJavaCSV(Blackhole bh) throws Exception { public int parseJavaCSV(final Blackhole bh) throws Exception {
BufferedReader in = getReader(); 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'); reader.setRecordDelimiter('\n');
int count = 0; int count = 0;
@ -152,10 +152,10 @@ public class CSVBenchmark {
} }
@Benchmark @Benchmark
public int parseOpenCSV(Blackhole bh) throws Exception { public int parseOpenCSV(final Blackhole bh) throws Exception {
BufferedReader in = getReader(); 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; int count = 0;
while (reader.readNext() != null) { while (reader.readNext() != null) {
@ -168,13 +168,13 @@ public class CSVBenchmark {
} }
@Benchmark @Benchmark
public int parseSkifeCSV(Blackhole bh) throws Exception { public int parseSkifeCSV(final Blackhole bh) throws Exception {
BufferedReader in = getReader(); 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(','); reader.setSeperator(',');
CountingReaderCallback callback = new CountingReaderCallback(); final CountingReaderCallback callback = new CountingReaderCallback();
reader.parse(in, callback); reader.parse(in, callback);
bh.consume(callback); bh.consume(callback);
@ -186,16 +186,16 @@ public class CSVBenchmark {
public int count = 0; public int count = 0;
@Override @Override
public void onRow(String[] fields) { public void onRow(final String[] fields) {
count++; count++;
} }
} }
@Benchmark @Benchmark
public int parseSuperCSV(Blackhole bh) throws Exception { public int parseSuperCSV(final Blackhole bh) throws Exception {
BufferedReader in = getReader(); final BufferedReader in = getReader();
CsvListReader reader = new CsvListReader(in, CsvPreference.STANDARD_PREFERENCE); final CsvListReader reader = new CsvListReader(in, CsvPreference.STANDARD_PREFERENCE);
int count = 0; int count = 0;
List<String> record = null; List<String> record = null;

View File

@ -395,7 +395,7 @@ public class CSVParserTest {
final String code = "A,B,C,,\r\na,b,c,d,e\r\n"; final String code = "A,B,C,,\r\na,b,c,d,e\r\n";
final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL.withHeader()); final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL.withHeader());
try { try {
for (CSVRecord record : parser.getRecords()) { for (final CSVRecord record : parser.getRecords()) {
Assert.assertEquals("a", record.get("A")); Assert.assertEquals("a", record.get("A"));
Assert.assertEquals("b", record.get("B")); Assert.assertEquals("b", record.get("B"));
Assert.assertEquals("c", record.get("C")); Assert.assertEquals("c", record.get("C"));
@ -917,7 +917,7 @@ public class CSVParserTest {
private void validateRecordPosition(final String lineSeparator) throws IOException { private void validateRecordPosition(final String lineSeparator) throws IOException {
final String nl = lineSeparator; // used as linebreak in values for better distinction 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 // to see if recordPosition correctly points to the enclosing quote
"'A" + nl + "A','B" + nl + "B',CC" + lineSeparator + "'A" + nl + "A','B" + nl + "B',CC" + lineSeparator +
// unicode test... not very relevant while operating on strings instead of bytes, but for // unicode test... not very relevant while operating on strings instead of bytes, but for

View File

@ -281,7 +281,7 @@ public class CSVPrinterTest {
} }
private void setUpTable(final Connection connection) throws SQLException { private void setUpTable(final Connection connection) throws SQLException {
Statement statement = connection.createStatement(); final Statement statement = connection.createStatement();
try { try {
statement.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"); statement.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
statement.execute("insert into TEST values(1, 'r1')"); statement.execute("insert into TEST values(1, 'r1')");