Skip to content

Commit 9893c09

Browse files
committed
[CSV-239] Cannot get headers in column order from CSVRecord.
* fix whitespace
1 parent 45dec89 commit 9893c09

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/main/java/org/apache/commons/csv/CSVParser.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,13 @@ private Map<String, Integer> createEmptyHeaderMap() {
447447
}
448448

449449
private static final class Headers {
450-
final Map<String,Integer> headerMap;
451-
final List<String> headerNames;
450+
final Map<String, Integer> headerMap;
451+
final List<String> headerNames;
452452

453-
Headers(Map<String, Integer> headerMap, List<String> headerNames) {
454-
this.headerMap = headerMap;
455-
this.headerNames = headerNames;
456-
}
453+
Headers(Map<String, Integer> headerMap, List<String> headerNames) {
454+
this.headerMap = headerMap;
455+
this.headerNames = headerNames;
456+
}
457457
}
458458

459459
/**
@@ -481,7 +481,7 @@ private Headers createHeaderMapAndHeaderNames() throws IOException {
481481
}
482482
headerRecord = formatHeader;
483483
}
484-
484+
485485
// build the name to index mappings
486486
if (headerRecord != null) {
487487
for (int i = 0; i < headerRecord.length; i++) {

src/test/java/org/apache/commons/csv/CSVParserTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,15 @@ public void testDefaultFormat() throws IOException {
294294

295295
@Test(expected = IllegalArgumentException.class)
296296
public void testDuplicateHeadersNotAllowed() throws Exception {
297-
CSVParser.parse("a,b,a\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader(new String[] {})
298-
.withAllowDuplicateHeaderNames(false));
297+
CSVParser.parse("a,b,a\n1,2,3\nx,y,z",
298+
CSVFormat.DEFAULT.withHeader(new String[] {}).withAllowDuplicateHeaderNames(false));
299299
}
300300

301301
@Test
302302
public void testDuplicateHeadersAllowedByDefault() throws Exception {
303303
CSVParser.parse("a,b,a\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader(new String[] {}));
304304
}
305-
305+
306306
@Test
307307
public void testEmptyFileHeaderParsing() throws Exception {
308308
try (final CSVParser parser = CSVParser.parse("", CSVFormat.DEFAULT.withFirstRecordAsHeader())) {
@@ -1169,9 +1169,8 @@ public void testTrim() throws Exception {
11691169

11701170
@Test
11711171
public void testRepeatedHeadersAreReturnedInCSVRecordHeaderNames() throws IOException {
1172-
final Reader in = new StringReader("header1,header2,header1\n1,2,3\n4,5,6");
1173-
final Iterator<CSVRecord> records = CSVFormat.DEFAULT.withFirstRecordAsHeader()
1174-
.withTrim().parse(in).iterator();
1172+
final Reader in = new StringReader("header1,header2,header1\n1,2,3\n4,5,6");
1173+
final Iterator<CSVRecord> records = CSVFormat.DEFAULT.withFirstRecordAsHeader().withTrim().parse(in).iterator();
11751174
final CSVRecord record = records.next();
11761175
assertEquals(Arrays.asList("header1", "header2", "header1"), record.getParser().getHeaderNames());
11771176
}

0 commit comments

Comments
 (0)