Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
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:
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();
Compare this with the current syntax:
// 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);
As a proof of concept I've written skeleton code which compiles (but needs completing).