commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benedikt Ritter (JIRA)" <>
Subject [jira] [Updated] (CSV-68) Use the Builder pattern for CSVFormat
Date Sat, 17 Nov 2012 12:53:12 GMT


Benedikt Ritter updated CSV-68:

    Attachment: CSV-68_20121117.patch

Hi again,

I have implemented equals and hashCode on CSVFormat, so that I could get rid of the assertEqualFormats
I did't add brackets in all if branches, to keep the code short. This may cause checkstyle
errors. Please comment how you feel about that.

I also addressed the issue with the header array reference. The header array is now copied
in the CSVFormat constructor. How ever, the reference to the header array can still escape
the CSVFormatBuilder. This may cause issues if CSVFormatBuilder instances are shared between
multiple threads. Do you think this is an issue that has to be addressed?

TIA for review,
> Use the Builder pattern for CSVFormat
> -------------------------------------
>                 Key: CSV-68
>                 URL:
>             Project: Commons CSV
>          Issue Type: Improvement
>            Reporter: Sebb
>         Attachments: CSV-68_20121111.patch, CSV-68_20121114.patch, CSV-68_20121115.patch,
CSV-68_20121117.patch, CSV-68.patch,,
> 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
>         .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,
> // 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:

View raw message