You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Stian Soiland-Reyes <st...@apache.org> on 2018/02/09 17:05:22 UTC

Re: [CSV][POLL] How to provide mutable records

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.

-- 
Stian Soiland-Reyes
The University of Manchester
http://www.esciencelab.org.uk/
http://orcid.org/0000-0001-9842-9718


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [CSV][POLL] How to provide mutable records

Posted by Stian Soiland-Reyes <st...@apache.org>.
On Mon, 12 Feb 2018 18:10:56 -0700, Gary Gregory <ga...@gmail.com> wrote:
> On Fri, Feb 9, 2018 at 10:05 AM, Stian Soiland-Reyes <st...@apache.org>
> I've not had time to review this yet but I hope to get to it sometimes this
> week.

Thanks. I'll wait for that before prepping a 1.6 RC so we get time to
decide if this is in or not.


-- 
Stian Soiland-Reyes
The University of Manchester
http://www.esciencelab.org.uk/
http://orcid.org/0000-0001-9842-9718



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [CSV][POLL] How to provide mutable records

Posted by Gary Gregory <ga...@gmail.com>.
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-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>