commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stian Soiland-Reyes <>
Subject Re: [CSV][POLL] How to provide mutable records
Date Fri, 09 Feb 2018 17:05:22 GMT
On Fri, 25 Aug 2017 19:19:58 +0100, Stian Soiland-Reyes <> wrote:
> This came up also for commons rdf where we also have everything immutable,
> which I think is a good principle to keep for modern Java 8 programming.
> So you need a mutator function like in (4) that either returns a new
> immutable (but changed) CSVRecord; or alternatively a different
> MutableCSVRecord that can then be built/frozen to a CSVRecord. (These can
> then share a common accessor interface for the passive functions)

Picking up this thread to consider this for CSV 1.6.

Not quite as elegant as above, but I made
some mutator functions withValue() in

for (CSVRecord r : csvparser) {
  CSVRecord rSoup = r.withValue(4, "soup")
                     .withValue(5, "fish");
  // original r is untouched and can be used again
  CSVRecord rBeans = r.withValue(3, "beans");

  List<CSVRecord> list;
  // Each now different

  // worried someone might touch your beans?

It's not clever enough (yet!) to resize the underlying array if you try to go
outside the existing columns. The existing parser seems to detect column number
(and hence record array size) per line so this might be weird for some
inconsistent CSV files.

Comments and changes on CSV-216 branch welcome.

Stian Soiland-Reyes
The University of Manchester

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message