Hi guys,
a while back we had this discussion [1] about the current state of the
CSVFormat API. We were still not completely happy with it and Oliver came
up with a new suggestion [2].
This weekend I finally had some time to hack something together. I've
created a mirror of CSV rev. 1484347 at github [3].
This proposal uses CSVFormatModifier objects to change a CSVFormat. The API
relies on static imports of factory methods for CSVFormatModifiers and
looks like the following:
CSVFormat modifed = CSVFormat.DEFAULT.with(
delimiter(';'),
noEscape(),
commentStart('#'));
So far I've implemented methods for changing delimiter, commentStart,
escape and quote policy (have a look at CSVFormatModifierTest). The
approach has the advantage of being short like the initial implementation,
while making sure that CSVFormat is immutable and validated at construction
time. The draw back however is, that it is a bit of a pain to get all the
static imports in place (at least this is my feeling with Eclipse, any
suggestions on how to work efficiently with static imports in eclipse are
appreciated :)
Now I'd like to ask you for feedback. Do you like this approach? Any
suggestions?
One thing I'm not sure about is MutableCSVFormat. Maybe this can be merged
together with CSVFormatModifier.
Regards,
Benedikt
[1] http://markmail.org/thread/o3s2a5hyj6xh4nzj
[2] http://markmail.org/message/vjjdbckwr4dlqp2b
[3] https://github.com/britter/apache-commons-csv-mirror
--
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter