Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 50D5710FF0 for ; Wed, 22 Jan 2014 16:28:19 +0000 (UTC) Received: (qmail 5585 invoked by uid 500); 22 Jan 2014 16:28:15 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 5381 invoked by uid 500); 22 Jan 2014 16:28:15 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 5373 invoked by uid 99); 22 Jan 2014 16:28:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Jan 2014 16:28:15 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of sjr@jdns.org designates 209.85.214.177 as permitted sender) Received: from [209.85.214.177] (HELO mail-ob0-f177.google.com) (209.85.214.177) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Jan 2014 16:28:09 +0000 Received: by mail-ob0-f177.google.com with SMTP id wp18so670154obc.22 for ; Wed, 22 Jan 2014 08:27:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=JMPpjYWDPG55lVhbQDOxXRocIKIHGnGXXsskCdeM/Dg=; b=A66i+nnca5FUIlcEV1DRFXmhPFW21ggsGobiBO6iDMREi86fEWM3gvzqzTUtniFirq 5CmVHzkykew9olLbmr1gRM5He7NSmTaL6AkO45XlhXULXp7kieThjuA4AbsNOrJC8w1L W6reHTqJS/uTqd9a/lLMmpAI2uY18hpoFwdWaMVpqK/SIr3gqaW9TlqWDOlEyWoOtDnE 0lAc7+ongGGv+R55m9iya23Y94eMqb8QI0WDFRymHuFHJ2qcDGSAiE9Bdo79dtjvIU9B Om98EeIV7tvTEEvz6xCAAAC7CQk9KW031/o/6BKPjg9U39oR5acZSefDlupSIlblpMnF Zu2w== X-Gm-Message-State: ALoCoQkf4x9kfc9pFh780EZZ5YcsNAlDr0hFtZl7uw3+BDXvacoam7Lvcuum3UBw/QK3sntLLH31 MIME-Version: 1.0 X-Received: by 10.60.33.7 with SMTP id n7mr2037711oei.25.1390408068293; Wed, 22 Jan 2014 08:27:48 -0800 (PST) Received: by 10.60.17.201 with HTTP; Wed, 22 Jan 2014 08:27:48 -0800 (PST) In-Reply-To: <20140122100325.503119h1watnn3d9@secure172.sgcpanel.com> References: <52DE7488.3000801@apache.org> <52DE7D20.2070708@apache.org> <52DFC13F.6080009@apache.org> <52DFCA93.9050905@sandglass-software.com> <20140122084042.18813q7v522dlfu2@secure172.sgcpanel.com> <20140122090402.18356amidyzttfqa@secure172.sgcpanel.com> <20140122100325.503119h1watnn3d9@secure172.sgcpanel.com> Date: Wed, 22 Jan 2014 08:27:48 -0800 Message-ID: Subject: Re: [csv] CSVRecord and Map From: James Ring To: Commons Developers List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org There is nothing that says Map must be mutable, even the javadoc says: "put - Associates the specified value with the specified key in this map (optional operation)." On Wed, Jan 22, 2014 at 8:03 AM, wrot= e: > There is no question your use case is convenient, but it violates the > contract that a CSV record is read-only. Calling put() on a CSV record is= a > mutating operation. > > So, is a CSV record read-only or not? > > > -Adrian > > Quoting Gary Gregory : > >> On Wed, Jan 22, 2014 at 10:04 AM, >> wrote: >> >>> I disagree. If the CSV record is read-only, then the List and Map >>> representations of the CSV record should be read-only too. Making those >>> representations writable is confusing - it gives the impression you are >>> modifying the CSV record when in fact you are not. >>> >>> I don't see how it restricts their usability. >>> >> >> I guess I should have started with another use-case: take a CSV, remove = a >> column, and compute a new column. >> >> Right now I can do (to try, add this to CSVRecordTest): >> >> @Test >> public void testRemoveAndAddColumns() throws IOException { >> // do: >> final CSVPrinter printer =3D new CSVPrinter(new StringBuilder(), >> CSVFormat.DEFAULT); >> final Map map =3D recordWithHeader.toMap(); >> map.remove("OldColumn"); >> map.put("NewColumn", "NewValue"); >> // check: >> final ArrayList list =3D new >> ArrayList(map.values()); >> Collections.sort(list); >> printer.printRecord(list); >> Assert.assertEquals("A,B,C,NewValue" + >> CSVFormat.DEFAULT.getRecordSeparator(), printer.getOut().toString()); >> } >> >> I would have to create a wasteful temp Map if the Map I get from the >> record >> is read-only. This code is bad enough. >> >> If the record is a Map, there is no song and dance at all: >> >> // do: >> final CSVPrinter printer =3D new CSVPrinter(new StringBuilder(), >> CSVFormat.DEFAULT); >> recordWithHeader.remove("OldColumn"); >> recordWithHeader.put("NewColumn", "NewValue"); >> // check: >> printer.printRecord(recordWithHeader); >> Assert.assertEquals("A,B,C,NewValue" + >> CSVFormat.DEFAULT.getRecordSeparator(), printer.getOut().toString()); >> >> >> If you want a special kind of Map (a blinking read-only map ;), you can >> call putIn(Map). >> >> Gary >> >>> >>> -Adrian >>> >>> Quoting Gary Gregory : >>> >>> On Wed, Jan 22, 2014 at 9:40 AM, >>>> >>>> wrote: >>>> >>>> CORRECTION: The patch in the Jira issue is a simplified version of >>>> Gary's >>>>> >>>>> implementation. >>>>> >>>>> I started with the design I proposed - an inner class Map >>>>> implementation >>>>> backed by CSVRecord, but then implementing entrySet() and such became >>>>> complicated. So I changed it to the inner class being backed by a >>>>> HashMap, >>>>> then reduced that to a simplified version of Gray's implementation. >>>>> >>>>> I apologize for the confusion. >>>>> >>>>> >>>> I do not see the point of making the new objects (list, map) read-only= . >>>> Since the objects are not connected to the record, there should be no >>>> expectancy of synchronizing the map with the record. There are "to" >>>> methods >>>> after all. This just restricts the usability of the objects. >>>> >>>> Gary >>>> >>>> >>>>> -Adrian >>>>> >>>>> >>>>> Quoting Adrian Crum : >>>>> >>>>> I agree with Emmanuel. We don't want CSVRecord to devolve into a god >>>>> >>>>>> class that tries to be everything to everybody. "Do only one thing, >>>>>> and >>>>>> do >>>>>> it really well" is the design pattern I prefer. >>>>>> >>>>>> I created a patch for the design I proposed a few days ago. Please >>>>>> consider using it. >>>>>> >>>>>> https://issues.apache.org/jira/browse/CSV-104 >>>>>> >>>>>> >>>>>> Adrian Crum >>>>>> Sandglass Software >>>>>> www.sandglass-software.com >>>>>> >>>>>> On 1/22/2014 8:01 AM, Emmanuel Bourg wrote: >>>>>> >>>>>> Le 21/01/2014 15:08, Gary Gregory a =E9crit : >>>>>>> >>>>>>> >>>>>>> This kind of complication is unnecessary IMO, why not just have th= e >>>>>>> >>>>>>>> record >>>>>>>> implement Map? >>>>>>>> >>>>>>>> >>>>>>> Because a record is neither a List nor a Map. >>>>>>> >>>>>>> A map decorator isn't that complicated, and the work has already be= en >>>>>>> done in [configuration]. It would be trivial to adapt the code to >>>>>>> [csv]. >>>>>>> >>>>>>> Emmanuel Bourg >>>>>>> >>>>>>> >>>>>>> -------------------------------------------------------------------= -- >>>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org >>>>>>> For additional commands, e-mail: dev-help@commons.apache.org >>>>>>> >>>>>>> >>>>>>> >>>>>>> -------------------------------------------------------------------= -- >>>>>> >>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org >>>>>> For additional commands, e-mail: dev-help@commons.apache.org >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org >>>>> For additional commands, e-mail: dev-help@commons.apache.org >>>>> >>>>> >>>>> >>>> >>>> -- >>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org >>>> Java Persistence with Hibernate, Second Edition>>> com/bauer3/> >>>> JUnit in Action, Second Edition >>>> Spring Batch in Action >>>> >>>> Blog: http://garygregory.wordpress.com >>>> Home: http://garygregory.com/ >>>> Tweet! http://twitter.com/GaryGregory >>>> >>>> >>> >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org >>> For additional commands, e-mail: dev-help@commons.apache.org >>> >>> >> >> >> -- >> E-Mail: garydgregory@gmail.com | ggregory@apache.org >> Java Persistence with Hibernate, Second >> Edition >> JUnit in Action, Second Edition >> Spring Batch in Action >> Blog: http://garygregory.wordpress.com >> Home: http://garygregory.com/ >> Tweet! http://twitter.com/GaryGregory >> > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org