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:
parent
0e91beab00
commit
6d5611f793
|
@ -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
|
||||
* @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<CSVRecord>, Closeable {
|
|||
*/
|
||||
public List<CSVRecord> getRecords() throws IOException {
|
||||
CSVRecord rec;
|
||||
List<CSVRecord> records = new ArrayList<CSVRecord>();
|
||||
final List<CSVRecord> records = new ArrayList<CSVRecord>();
|
||||
while ((rec = this.nextRecord()) != null) {
|
||||
records.add(rec);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public final class CSVRecord implements Serializable, Iterable<String> {
|
|||
private final String[] values;
|
||||
|
||||
CSVRecord(final String[] values, final Map<String, Integer> 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;
|
||||
|
|
|
@ -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<String> record = null;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')");
|
||||
|
|
Loading…
Reference in New Issue