From 74339e492039c78cf89f2b5eb3aaaaa02db1b394 Mon Sep 17 00:00:00 2001
From: ymedina
@@ -666,6 +679,7 @@ public int hashCode() {
result = prime * result + ((escapeCharacter == null) ? 0 : escapeCharacter.hashCode());
result = prime * result + ((nullString == null) ? 0 : nullString.hashCode());
result = prime * result + (ignoreSurroundingSpaces ? 1231 : 1237);
+ result = prime * result + (ignoreHeaderCase ? 1231 : 1237);
result = prime * result + (ignoreEmptyLines ? 1231 : 1237);
result = prime * result + (skipHeaderRecord ? 1231 : 1237);
result = prime * result + ((recordSeparator == null) ? 0 : recordSeparator.hashCode());
@@ -775,6 +789,9 @@ public String toString() {
if (getIgnoreSurroundingSpaces()) {
sb.append(" SurroundingSpaces:ignored");
}
+ if (getIgnoreHeaderCase()) {
+ sb.append(" IgnoreHeaderCase:ignored");
+ }
sb.append(" SkipHeaderRecord:").append(skipHeaderRecord);
if (headerComments != null) {
sb.append(' ');
@@ -870,7 +887,7 @@ public CSVFormat withCommentMarker(final Character commentMarker) {
}
return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
- skipHeaderRecord, allowMissingColumnNames);
+ skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase);
}
/**
@@ -888,7 +905,7 @@ public CSVFormat withDelimiter(final char delimiter) {
}
return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
- skipHeaderRecord, allowMissingColumnNames);
+ skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase);
}
/**
@@ -919,7 +936,7 @@ public CSVFormat withEscape(final Character escape) {
}
return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escape, ignoreSurroundingSpaces,
ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord,
- allowMissingColumnNames);
+ allowMissingColumnNames, ignoreHeaderCase);
}
/**
@@ -947,7 +964,7 @@ public CSVFormat withEscape(final Character escape) {
public CSVFormat withHeader(final String... header) {
return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
- skipHeaderRecord, allowMissingColumnNames);
+ skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase);
}
/**
@@ -1015,7 +1032,7 @@ public CSVFormat withHeader(final ResultSetMetaData metaData) throws SQLExceptio
}
return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, labels,
- skipHeaderRecord, allowMissingColumnNames);
+ skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase);
}
/**
@@ -1036,7 +1053,7 @@ public CSVFormat withHeader(final ResultSetMetaData metaData) throws SQLExceptio
public CSVFormat withHeaderComments(final Object... headerComments) {
return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
- skipHeaderRecord, allowMissingColumnNames);
+ skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase);
}
/**
@@ -1061,7 +1078,7 @@ public CSVFormat withAllowMissingColumnNames() {
public CSVFormat withAllowMissingColumnNames(final boolean allowMissingColumnNames) {
return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
- skipHeaderRecord, allowMissingColumnNames);
+ skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase);
}
/**
@@ -1086,7 +1103,7 @@ public CSVFormat withIgnoreEmptyLines() {
public CSVFormat withIgnoreEmptyLines(final boolean ignoreEmptyLines) {
return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
- skipHeaderRecord, allowMissingColumnNames);
+ skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase);
}
/**
@@ -1111,7 +1128,32 @@ public CSVFormat withIgnoreSurroundingSpaces() {
public CSVFormat withIgnoreSurroundingSpaces(final boolean ignoreSurroundingSpaces) {
return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
- skipHeaderRecord, allowMissingColumnNames);
+ skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase);
+ }
+
+ /**
+ * Sets the header ignore case behavior to {@code true}.
+ *
+ * @return A new CSVFormat that will ignore case header name.
+ * @see #withIgnoreHeaderCase(boolean)
+ * @since ?
+ */
+ public CSVFormat withIgnoreHeaderCase() {
+ return this.withIgnoreHeaderCase(true);
+ }
+
+ /**
+ * Sets if header names should be accessed ignoring case.
+ *
+ * @param ignoreHeaderCase
+ * the case mapping behavior, {@code true} to access name/values, {@code false} to leave the
+ * mapping as is.
+ * @return A new CSVFormat that will ignore case header name if specified as {@code true}
+ */
+ public CSVFormat withIgnoreHeaderCase(final boolean ignoreHeaderCase) {
+ return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,
+ ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
+ skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase);
}
/**
@@ -1132,7 +1174,7 @@ public CSVFormat withIgnoreSurroundingSpaces(final boolean ignoreSurroundingSpac
public CSVFormat withNullString(final String nullString) {
return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
- skipHeaderRecord, allowMissingColumnNames);
+ skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase);
}
/**
@@ -1163,7 +1205,7 @@ public CSVFormat withQuote(final Character quoteChar) {
}
return new CSVFormat(delimiter, quoteChar, quoteMode, commentMarker, escapeCharacter, ignoreSurroundingSpaces,
ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord,
- allowMissingColumnNames);
+ allowMissingColumnNames, ignoreHeaderCase);
}
/**
@@ -1177,7 +1219,7 @@ public CSVFormat withQuote(final Character quoteChar) {
public CSVFormat withQuoteMode(final QuoteMode quoteModePolicy) {
return new CSVFormat(delimiter, quoteCharacter, quoteModePolicy, commentMarker, escapeCharacter,
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
- skipHeaderRecord, allowMissingColumnNames);
+ skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase);
}
/**
@@ -1215,7 +1257,7 @@ public CSVFormat withRecordSeparator(final char recordSeparator) {
public CSVFormat withRecordSeparator(final String recordSeparator) {
return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
- skipHeaderRecord, allowMissingColumnNames);
+ skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase);
}
/**
@@ -1242,6 +1284,6 @@ public CSVFormat withSkipHeaderRecord() {
public CSVFormat withSkipHeaderRecord(final boolean skipHeaderRecord) {
return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
- skipHeaderRecord, allowMissingColumnNames);
+ skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase);
}
}
diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java
index 220ae92ba3..66a67b6a55 100644
--- a/src/main/java/org/apache/commons/csv/CSVParser.java
+++ b/src/main/java/org/apache/commons/csv/CSVParser.java
@@ -33,6 +33,7 @@
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
+import java.util.TreeMap;
import static org.apache.commons.csv.Token.Type.*;
@@ -378,7 +379,9 @@ private Map