Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 73083 invoked from network); 30 Apr 2003 16:37:25 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 30 Apr 2003 16:37:25 -0000 Received: (qmail 3759 invoked by uid 97); 30 Apr 2003 16:39:27 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@nagoya.betaversion.org Received: (qmail 3752 invoked from network); 30 Apr 2003 16:39:26 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 30 Apr 2003 16:39:26 -0000 Received: (qmail 72899 invoked by uid 500); 30 Apr 2003 16:37:23 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 72888 invoked from network); 30 Apr 2003 16:37:23 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 30 Apr 2003 16:37:23 -0000 Received: (qmail 73958 invoked by uid 1304); 30 Apr 2003 16:37:20 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 30 Apr 2003 16:37:20 -0000 Date: Wed, 30 Apr 2003 09:37:19 -0700 (PDT) From: Rodney Waldhoff To: Jakarta Commons Developers List Subject: RE: [COLLECTIONS] Some more lobbying for the OrderedSet class In-Reply-To: <73E71EF16978D51197180002A56022D20743C4E5@ngmnt4mbx03.uk.capitalone.com> Message-ID: <20030430092832.G57842@icarus.apache.org> References: <73E71EF16978D51197180002A56022D20743C4E5@ngmnt4mbx03.uk.capitalone.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Rating: localhost 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N On Wed, 30 Apr 2003, Hope, Matthew wrote: > The contract of the Set.equals() method is conformed to by the List.equals() > method But the contract of List.equals is not compatiable with Set.equals, since List cares about order, but Set does not. This means that for some ListSet: listSet := { 1, 2, 3 } and a Set set := { 3, 2, 1 } (assume { a, b, c } means that the iterator() method returns elements in that order). Assuming ListSet implements Set, then: set.equals(listSet) is true but: listSet.equals(set) is false, which is a violation of the general Object.equals contract. This limitation is noted in the Collection.equals method documentation, which reads in part: "it is not possible to write a class that correctly implements both the Set and List interfaces". - Rod > > Therefore by default using the List implementation is safe > > However it would make sense to have the equals method explicityly meaningful > via: > > public boolean equals(Object o) > { > if (o instanceof ListSet) > { > ListSet otherSet = (ListSet)o; > if (otherSet.size() != size()) > { > return false; > } > > for (int i = 0; i < size(); i++) > { > if (!equalsOrBothNull(get(i), otherSet.get(i))) > { > return false; > } > } > return true; > > } > return false; > } > > // implement accordingly > public boolean equalsAccordingToSet(Object o); > public boolean equalsAccordingToList(Object o); > > private boolean equalsOrBothNull(Object o1, Object o2) > { > if (o1 == null && o2 == null) > { > return true; > } > if (o1 != null) > { > return o1.equals(o2); > } > return o2.equals(01); > } > > Or alternatively just guarantee that any object capable of providing an > iterator returns all and only all of the objects in this in the same order > as this... > > Matt > > -----Original Message----- > From: Rodney Waldhoff [mailto:rwaldhoff@apache.org] > Sent: 30 April 2003 16:57 > To: Jakarta Commons Developers List > Cc: bayard@generationjava.com > Subject: Re: [COLLECTIONS] Some more lobbying for the OrderedSet class > > > I agree that ListSet is a useful an intuitive concept. Unfortunately, > it's not possible to fully and correctly implement both interfaces, by > nature of the List.equals and Set.equals contracts. We may want to create > our own ListSet equality definition, or pick one of List.equals or > Set.equals as our defintion of ListSet equality, and make that limitation > very clear in the documentation. If we do the latter, let's say List, > then we'll probably want to define a ListSet.equalsSet(Set):boolean > method and/or a ListSet.toSet():Set method. > > - Rod > > On Tue, 29 Apr 2003 ericpabst@discoverfinancial.com wrote: > > > I strongly agree that a ListSet interface that extends both List and Set > is > > the most intuitive way to go. "List" and "Set" are understood by Java > > developers anywhere and to have a "ListSet" interface would make it very > > clear what it means. > > > > Eric Pabst > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > > For additional commands, e-mail: commons-dev-help@jakarta.apache.org > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-dev-help@jakarta.apache.org > > ************************************************************************** > The information transmitted herewith is sensitive information intended only > for use by the individual or entity to which it is addressed. If the reader > of this message is not the intended recipient, you are hereby notified that > any review, retransmission, dissemination, distribution, copying or other > use of, or taking of any action in reliance upon this information is > strictly prohibited. If you have received this communication in error, > please contact the sender and delete the material from your computer. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-dev-help@jakarta.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org