On Thu, Jan 16, 2014 at 7:24 PM, sebb <seb...@gmail.com> wrote: > On 16 January 2014 20:58, Gary Gregory <garydgreg...@gmail.com> wrote: > > On Thu, Jan 16, 2014 at 7:49 AM, Emmanuel Bourg <ebo...@apache.org> > wrote: > > > >> Le 15/01/2014 14:04, Gary Gregory a écrit : > >> > >> > Uh, I want to go the other way around. See my use case. > >> > >> Why isn't this suitable to your use case? You could write: > >> > >> factory.create(record.toMap()); > >> > >> and then remove the create(CSVRecord) method with the duplicated > >> implementation. > >> > >> What am I missing? > >> > > > > That would work. What is still not clean or OO is that toMap() means > > nothing when no headers are defined. > > > > I've split the record into a mapped record subclass here: > > > > https://issues.apache.org/jira/browse/CSV-104 > > > > Thoughts? > > > > We can still have toMap() implemented on top of the code now, but it > would > > have to return null if there are no headers. > > Why not return an empty Map? >
An empty map is, well, empty but the record is not empty, so that's kinda confusing, whereas null is clearly something that does exist. If toMap() is only in the subclass, then there is no problem. The alternative is to create a real map with columns name "Column1", "Column2", and so on. But then that would be confusing because record.get("Column1) would give you null whereas record.toMap().get("Column1") would give you a value. Then we get to talk about having "Column1", "Column2"... as the default column names if none are provided... kinda too clever. All of this to say that over time it is likely as we need to provide more APIs, and it seems easier to say null than an empty structure. First toMap(), then toProperties() and so on. The KISS solution is toMap() -> null for unmapped records IMO. Gary > > > Gary > > > > > >> > >> Emmanuel Bourg > >> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > >> For additional commands, e-mail: dev-h...@commons.apache.org > >> > >> > > > > > > -- > > E-Mail: garydgreg...@gmail.com | ggreg...@apache.org > > Java Persistence with Hibernate, Second Edition< > http://www.manning.com/bauer3/> > > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> > > Spring Batch in Action <http://www.manning.com/templier/> > > Blog: http://garygregory.wordpress.com > > Home: http://garygregory.com/ > > Tweet! http://twitter.com/GaryGregory > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > For additional commands, e-mail: dev-h...@commons.apache.org > > -- E-Mail: garydgreg...@gmail.com | ggreg...@apache.org Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> Spring Batch in Action <http://www.manning.com/templier/> Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory