Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 60454 invoked from network); 11 Feb 2003 13:35:24 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 11 Feb 2003 13:35:24 -0000 Received: (qmail 66 invoked by uid 97); 11 Feb 2003 13:36:54 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@nagoya.betaversion.org Received: (qmail 59 invoked from network); 11 Feb 2003 13:36:54 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 11 Feb 2003 13:36:54 -0000 Received: (qmail 60250 invoked by uid 500); 11 Feb 2003 13:35:21 -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 60238 invoked from network); 11 Feb 2003 13:35:21 -0000 Received: from puget.esil.univ-mrs.fr (139.124.41.103) by daedalus.apache.org with SMTP; 11 Feb 2003 13:35:21 -0000 Received: from puget.esil.univ-mrs.fr (localhost.esil.univ-mrs.fr [127.0.0.1]) by puget.esil.univ-mrs.fr (8.12.6/8.12.6) with ESMTP id h1BDb4Zl096941; Tue, 11 Feb 2003 14:37:04 +0100 (CET) (envelope-from herve.quiroz@esil.univ-mrs.fr) Received: from localhost (rv@localhost) by puget.esil.univ-mrs.fr (8.12.6/8.12.6/Submit) with ESMTP id h1BDb4b1096938; Tue, 11 Feb 2003 14:37:04 +0100 (CET) X-Authentication-Warning: puget.esil.univ-mrs.fr: rv owned process doing -bs Date: Tue, 11 Feb 2003 14:37:03 +0100 (CET) From: Herve Quiroz X-X-Sender: rv@puget.esil.univ-mrs.fr To: BluePhelix@web.de cc: jakarta-commons-dev@apache.org Subject: Re: [collections] filtering and splitting collections In-Reply-To: <200302080921.h189LJe05210@mailgate5.cinetic.de> Message-ID: <20030211120720.W96609@puget.esil.univ-mrs.fr> References: <200302080921.h189LJe05210@mailgate5.cinetic.de> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Hi, Well, I am not a commiter but I will give my opinion on the subject anyway. I am not a fan of OUT parameters in method calls. So I would be in favor of (c). First because (a) would mean API change. Also the returned Collection could be mistaken as the good ones from the collection given in parameter (this would not happen if everybody read carefully the API docs anyway). Still there is another flavor : Collection addAll(Collection c, Predicate p) which fills the returned collection with elements from c according to p. This method would either be a member of a sub-interface of Collection. Or as static method in CollectionUtils with a third parameter as the destination collection. I know I said I don't like OUT parameters but here it is also returned so it's not a problem IMHO. Then if you have some sort of OppositePredicate(Predicate p) you can split a collection in two others with two calls : Collection s; Predicate p; Collection greenOnes=new Collection().addAll(s, p); Collection notSoGreen=new Collection().addAll(s, new OppositePredicate(p)); Well, I'm not sure of this one... Just my two cents. Regards, Herve On Sat, 8 Feb 2003 BluePhelix@web.de wrote: > 1. Splitting a collection > [...] > I recommend to provide a method within CollectionUtils which splits a collection > using a given predicate. The idea is to iterate through the collection only > once. The problem is that a method with two return values can't be easily > understood. But, in my opinion, splitting a collection is a pretty basic thing. > > There are three flavours to realize a collection split I would like to discuss: > (a) changing the existing CollectionUtils.filter method to return the collection > of rejected items > (b) adding a CollectionUtils.filter method with a 3rd parameter for the > collection of rejected items > (c) explicitly introducing a method called #filterOut or #split > > I would agree most with solution (b): > > public static void filter(Collection collection, > Predicate predicate, > Collection rejectedOutputCollection) { > if (collection != null && predicate != null) { > for (Iterator it = collection.iterator(); it.hasNext();) { > Object item = it.next(); > if (predicate.evaluate(item) == false) { > it.remove(); > rejectedOutputCollection.add(item);}}}}} > > What do you think about that? > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org