[ 
https://issues.apache.org/jira/browse/CSV-68?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13499482#comment-13499482
 ] 

Gary Gregory commented on CSV-68:
---------------------------------

Patch tweaked and applied 
(https://issues.apache.org/jira/secure/attachment/12553894/CSV-68_20121117.patch).
 Thank you!

{noformat}
commit -m "[CSV-68] Use the Builder pattern for CSVFormat." 
C:/svn/org/apache/commons/trunks-proper/csv/src/test/java/org/apache/commons/csv/CSVFormatTest.java
 
C:/svn/org/apache/commons/trunks-proper/csv/src/test/java/org/apache/commons/csv/CSVFormatBuilderTest.java
 
C:/svn/org/apache/commons/trunks-proper/csv/src/main/java/org/apache/commons/csv/CSVFormat.java
    Sending        
C:/svn/org/apache/commons/trunks-proper/csv/src/main/java/org/apache/commons/csv/CSVFormat.java
    Sending        
C:/svn/org/apache/commons/trunks-proper/csv/src/test/java/org/apache/commons/csv/CSVFormatBuilderTest.java
    Sending        
C:/svn/org/apache/commons/trunks-proper/csv/src/test/java/org/apache/commons/csv/CSVFormatTest.java
    Transmitting file data ...
    Committed revision 1410759.
{noformat}


                
> Use the Builder pattern for CSVFormat
> -------------------------------------
>
>                 Key: CSV-68
>                 URL: https://issues.apache.org/jira/browse/CSV-68
>             Project: Commons CSV
>          Issue Type: Improvement
>            Reporter: Sebb
>             Fix For: 1.0
>
>         Attachments: CSV-68_20121111.patch, CSV-68_20121114.patch, 
> CSV-68_20121115.patch, CSV-68_20121117.patch, CSV-68.patch, CSVFormat2.java, 
> CVSFormat2Main.java
>
>
> Using a builder pattern to create CSVFormat instances would allow the 
> settings to be validated at creation time and would eliminate the need to 
> keep creating new CSVFormat instances whilst still allowing the class to be 
> immutable.
> A possible API is as follows:
> {code}
> CSVFormat DEFAULT = CSVFormat.init(',') // delimiter is required
>         .withEncapsulator('"')
>         .withLeadingSpacesIgnored(true)
>         .withTrailingSpacesIgnored(true)
>         .withEmptyLinesIgnored(true)
>         .withLineSeparator("\r\n") // optional, as it would be the default
>         .build();
> CSVFormat format = CSVFormat.init(CSVFormat.DEFAULT) // alternatively start 
> with pre-defined format
>         .withSurroundingSpacesIgnored(false)
>         .build();
> {code}
> Compare this with the current syntax:
> {code}
> // internal syntax; not easy to determine what all the parameters do
> CSVFormat DEFAULT1 = new CSVFormat(',', '"', DISABLED, DISABLED, true, true, 
> false, true, CRLF);
> // external syntax
> CSVFormat format = CSVFormat.DEFAULT.withSurroundingSpacesIgnored(false);
> {code}
> As a proof of concept I've written skeleton code which compiles (but needs 
> completing).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to