On Fri, Feb 9, 2018 at 10:05 AM, Stian Soiland-Reyes <st...@apache.org> wrote:
> On Fri, 25 Aug 2017 19:19:58 +0100, Stian Soiland-Reyes <st...@apache.org> > 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 > https://github.com/apache/commons-csv/pull/25 > > > 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 > someList.add(r); > someList.add(rSoup); > someList.add(rBeans); > > // worried someone might touch your beans? > consumeCSVRecord(rBeans.immutable()) > } > > 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. > Hi Stian, I've not had time to review this yet but I hope to get to it sometimes this week. Gary > > -- > Stian Soiland-Reyes > The University of Manchester > http://www.esciencelab.org.uk/ > http://orcid.org/0000-0001-9842-9718 > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > For additional commands, e-mail: dev-h...@commons.apache.org > >