Author: sebb
Date: Wed Mar 21 16:01:31 2012
New Revision: 1303455
URL: http://svn.apache.org/viewvc?rev=1303455&view=rev
Log:
headerMapping is only created once, so make it final
Modified:
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java
Modified:
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java
URL:
http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java?rev=1303455&r1=1303454&r2=1303455&view=diff
==============================================================================
---
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java
(original)
+++
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java
Wed Mar 21 16:01:31 2012
@@ -64,7 +64,7 @@ import static org.apache.commons.csv.CSV
public class CSVParser implements Iterable<CSVRecord> {
private final CSVLexer lexer;
- private Map<String, Integer> headerMapping;
+ private final Map<String, Integer> headerMapping;
// the following objects are shared to reduce garbage
@@ -94,7 +94,7 @@ public class CSVParser implements Iterab
this.lexer = new CSVLexer(format, new ExtendedBufferedReader(input));
- initializeHeader(format);
+ this.headerMapping = initializeHeader(format);
}
/**
@@ -172,9 +172,10 @@ public class CSVParser implements Iterab
/**
* Initializes the name to index mapping if the format defines a header.
*/
- private void initializeHeader(CSVFormat format) throws IOException {
+ private Map<String, Integer> initializeHeader(CSVFormat format) throws
IOException {
+ Map<String, Integer> hdrMap = null;
if (format.getHeader() != null) {
- headerMapping = new HashMap<String, Integer>();
+ hdrMap = new HashMap<String, Integer>();
String[] header = null;
if (format.getHeader().length == 0) {
@@ -190,10 +191,11 @@ public class CSVParser implements Iterab
// build the name to index mappings
if (header != null) {
for (int i = 0; i < header.length; i++) {
- headerMapping.put(header[i], Integer.valueOf(i));
+ hdrMap.put(header[i], Integer.valueOf(i));
}
}
}
+ return hdrMap;
}
/**