CSV-179: Add shortcut method for using first record as header to CSVFormat
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1742175 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1813f2663d
commit
b6f0655a71
|
@ -39,6 +39,7 @@
|
|||
</properties>
|
||||
<body>
|
||||
<release version="1.3" date="2016-MM-DD" description="Feature and bug fix release">
|
||||
<action issue="CSV-179" type="add" dev="britter">Add shortcut method for using first record as header to CSVFormat</action>
|
||||
<action issue="CSV-180" type="add" dev="britter">Add withHeader(Class<? extends Enum>) to CSVFormat</action>
|
||||
<action issue="CSV-167" type="update" dev="sebb" due-to="Rene">Comment line hides next record; update Javadoc to make behaviour clear</action>
|
||||
<action issue="CSV-153" type="update" dev="britter" due-to="Wren">CSVPrinter doesn't skip creation of header record if skipHeaderRecord is set to true</action>
|
||||
|
|
|
@ -1074,6 +1074,25 @@ public final class CSVFormat implements Serializable {
|
|||
allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@code CSVFormat} using the first record as header.
|
||||
*
|
||||
* <p>
|
||||
* Calling this method is equivalent to calling:
|
||||
* </p>
|
||||
* <pre>
|
||||
* CSVFormat format = aFormat.withHeader().withSkipHeaderRecord();
|
||||
* </pre>
|
||||
*
|
||||
* @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:
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue