This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-csv.git
The following commit(s) were added to refs/heads/master by this push: new 282f211 [CSV-239] Cannot get headers in column order from CSVRecord. 282f211 is described below commit 282f21139408d10253b4a9c32a681c05a8d5ef17 Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Mon May 20 08:10:49 2019 -0400 [CSV-239] Cannot get headers in column order from CSVRecord. - Redo header names as an read-only list. --- src/main/java/org/apache/commons/csv/CSVParser.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index a735df0..95dbfc6 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.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -183,9 +184,13 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable { } static List<String> createHeaderNames(final Map<String, Integer> headerMap) { + // @formatter:off return headerMap == null ? null - : headerMap.entrySet().stream().sorted(Map.Entry.comparingByValue()).map(Map.Entry::getKey) - .collect(Collectors.toList()); + : headerMap.entrySet().stream() + .sorted(Map.Entry.comparingByValue()) + .map(Map.Entry::getKey) + .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); + // @formatter:on } /** @@ -543,13 +548,13 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable { } /** - * Returns a copy of the header names that iterates in column order. + * Returns a read-only list of header names that iterates in column order. * - * @return a copy of the header names that iterates in column order. + * @return read-only list of header names that iterates in column order. * @since 1.7 */ public List<String> getHeaderNames() { - return new ArrayList<>(headerNames); + return headerNames; } /**