[
https://issues.apache.org/jira/browse/CSV-68?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13231930#comment-13231930
]
Sebb commented on CSV-68:
-------------------------
I've just discovered another disadvantage of the current code.
Removal of unicode escaping required changes to every single constructor call
in CSVFormat, of which there are a lot.
It was also necessary to be very careful to remove the correct parameter in the
predefined formats and test cases.
Similarly when adding a new parameter, a lot of code has to be changed.
With the proposed builder pattern, the changes are much simpler, because there
is only one constructor call to change (and its parameters are named, so it's
obvious where it should be put).
> Use Builder pattern for CSVFormat
> ---------------------------------
>
> Key: CSV-68
> URL: https://issues.apache.org/jira/browse/CSV-68
> Project: Commons CSV
> Issue Type: Improvement
> Reporter: Sebb
> Attachments: 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:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira