diff --git a/src/changes/changes.xml b/src/changes/changes.xml index dbde654b..722ed206 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -39,6 +39,7 @@
+ * Calling this method is equivalent to calling: + *
+ *+ * CSVFormat format = aFormat.withHeader().withSkipHeaderRecord(); + *+ * + * @return A new CSVFormat that is equal to this but using the first record as header. + * @see #withSkipHeaderRecord(boolean) + * @see #withHeader(String...) + * @since 1.3 + */ + public CSVFormat withFirstRecordAsHeader() { + return withHeader().withSkipHeaderRecord(); + } + /** * Returns a new {@code CSVFormat} with the header of the format set from the result set metadata. The header can * either be parsed automatically from the input file with: diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java index 0196c436..ac4abf0b 100644 --- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java @@ -436,6 +436,13 @@ public class CSVFormatTest { assertEquals(CRLF, formatWithRecordSeparator.getRecordSeparator()); } + @Test + public void testWithFirstRecordAsHeader() throws Exception { + final CSVFormat formatWithFirstRecordAsHeader = CSVFormat.DEFAULT.withFirstRecordAsHeader(); + assertTrue(formatWithFirstRecordAsHeader.getSkipHeaderRecord()); + assertTrue(formatWithFirstRecordAsHeader.getHeader().length == 0); + } + public enum Header { Name, Email, Phone }