Skip to content

Commit 6b2a504

Browse files
committed
Add a toBuilder method to do:
CSVFormat format = CSVFormat.EXCEL.toBuilder().withHeader("Col1", "Col2", "Col3").build(); Instead of: CSVFormat format = CSVFormat.newBuilder(CSVFormat.EXCEL).withHeader("Col1", "Col2", "Col3").build(); git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1460254 13f79535-47bb-0310-9956-ffa450edef68
1 parent 68f4892 commit 6b2a504

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,15 @@ public boolean equals(final Object obj) {
470470
return true;
471471
}
472472

473+
/**
474+
* Creates a builder based on this format.
475+
*
476+
* @return a new builder
477+
*/
478+
public CSVFormatBuilder toBuilder() {
479+
return new CSVFormatBuilder(this);
480+
}
481+
473482
/**
474483
* Builds CSVFormat objects.
475484
*/

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public void testCopiedFormatIsEqualToOriginal() {
5959
public void testCopiedFormatWithChanges() {
6060
final CSVFormat newFormat = CSVFormat.newBuilder(RFC4180).withDelimiter('!').build();
6161
assertTrue(newFormat.getDelimiter() != RFC4180.getDelimiter());
62+
final CSVFormat newFormat2 = RFC4180.toBuilder().withDelimiter('!').build();
63+
assertTrue(newFormat2.getDelimiter() != RFC4180.getDelimiter());
6264
}
6365

6466
@Test

0 commit comments

Comments
 (0)