Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 80826 invoked from network); 28 May 2002 19:49:29 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 28 May 2002 19:49:29 -0000 Received: (qmail 6368 invoked by uid 97); 28 May 2002 19:49:32 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 6331 invoked by uid 97); 28 May 2002 19:49:31 -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 6317 invoked by uid 50); 28 May 2002 19:49:30 -0000 Date: 28 May 2002 19:49:30 -0000 Message-ID: <20020528194930.6316.qmail@nagoya.betaversion.org> From: bugzilla@apache.org To: commons-dev@jakarta.apache.org Cc: Subject: DO NOT REPLY [Bug 9467] New: - Bag interface violates Collection contract X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT . ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE. http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9467 Bag interface violates Collection contract Summary: Bag interface violates Collection contract Product: Commons Version: unspecified Platform: All OS/Version: All Status: NEW Severity: Minor Priority: Other Component: Collections AssignedTo: commons-dev@jakarta.apache.org ReportedBy: pjack@sfaf.org The following methods as defined by the Bag interface violate their corresponding definitions in the Collection interface: add(Object), addAll(Collection) The Collection interface specifies that the add method should return true if the collection changes as a result of the call. Since a bag's size always increases as a result of an add operation, Bag.add should always return true. The bag interface specifies that add(Object) will only return true if the object was not already in the unique set. remove(Object) The Collection interface states that only one occurrence of a given object should be removed as a result of this method. The Bag interface specifies that all occurrences will be removed. removeAll(Collection) retainAll(Collection) containsAll(Collection) The Collection specification does not respect cardinality for these methods; the Bag interface does. The add, addAll and remove methods can be fixed easily, and code relying on the old behavior can be rewritten simply using existing Bag methods: boolean r = bag.add(obj) can be replaced with: boolean r = !bag.contains(obj); bag.add(obj) And boolean r = bag.remove(obj) can be replaced with boolean r = bag.remove(obj, bag.getCount(obj)); The existing bulk operations could be implemented with static utility methods in CollectionUtils (or possibly BagUtils), which would allow a smooth migration path for code that relies on the current bulk operation behavior. -- To unsubscribe, e-mail: For additional commands, e-mail: