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 E1FA5BD8F for ; Mon, 16 Jan 2012 16:12:15 +0000 (UTC) Received: (qmail 6808 invoked by uid 500); 16 Jan 2012 16:12:15 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 6648 invoked by uid 500); 16 Jan 2012 16:12:14 -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 6640 invoked by uid 99); 16 Jan 2012 16:12:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Jan 2012 16:12:14 +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 (athena.apache.org: domain of gudnabrsam@gmail.com designates 209.85.210.43 as permitted sender) Received: from [209.85.210.43] (HELO mail-pz0-f43.google.com) (209.85.210.43) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Jan 2012 16:12:10 +0000 Received: by dadp15 with SMTP id p15so19133824dad.30 for ; Mon, 16 Jan 2012 08:11:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:content-type:content-transfer-encoding; bh=4kdtute22YfyK4rGQlzscD6VFss+wbW1LYCEGNr9scg=; b=JvaK9krtsAqYF/mYFcsWfJLN63V6KrvXkKqUZgJh7w0vxFbzWVFqoeVymThlWzrAFq kaUOE4WfMmAQcyDyDaWiQ8WQcESSUTL6WPC/AOc4nDR1RFBPEwmFJ0a9SJHRmRnFct/V Aa+YyaYDH57rIYfKQBsHAnlB5G1ESmYAn4yvs= MIME-Version: 1.0 Received: by 10.68.115.174 with SMTP id jp14mr27421345pbb.42.1326730310089; Mon, 16 Jan 2012 08:11:50 -0800 (PST) Received: by 10.68.42.69 with HTTP; Mon, 16 Jan 2012 08:11:50 -0800 (PST) Reply-To: gudnabrsam@gmail.com In-Reply-To: References: <4F12BF7B.3010809@systemoutprintln.de> <4F140349.1070806@systemoutprintln.de> Date: Mon, 16 Jan 2012 10:11:50 -0600 Message-ID: Subject: Re: [collections] suggestion for improvement: QueryableCollections From: Matt Benson To: Commons Developers List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Also, if you're interested in predicate-based APIs for filtering Iterables, check out the FilteredIterable class in Commons' unreleased [functor] component. Matt On Mon, Jan 16, 2012 at 9:50 AM, James Ring wrote: > I agree, I'm just saying you should seriously study the design of those > interfaces before you embark on a project like this. > > Adding a new API to a library like collections imposes a burden on > maintainers that far outweighs the initial cost of the implementation. Yo= u > should make sure the API is worth the cost. The guys on guava have spent > serious effort designing the APIs, it's just good software engineering to > duplicate as little of that effort as possible. > > As much as it may bother some people to hear it, I think commons should > cease feature additions on collections and fix bugs only. Guava is very > much superior, is favourably licensed and effort should be focused in one > place. > > Just my two cents. I'm not an active member of Jakarta commons, just an > interested third party. :-) > > Regards, > James > > -- sent from my phone, excuse typos > On Jan 16, 2012 3:00 AM, "Benedikt Ritter" wro= te: > >> Am 15.01.2012 20:23, schrieb James Ring: >> >>> Google Guava has all this and more, and it doesn't require an extension= to >>> ArrayList, any Iterable will do. >>> >>> http://google-collections.**googlecode.com/svn/trunk/** >>> javadoc/com/google/common/**collect/Iterables.html >>> >> >> Hi James, >> >> thanks for the response! I agree with you, that google guava does the sa= me >> and that it does it better. In fact I do think, that there are things, t= hat >> guava does even better than commons collections. For example using >> generics... >> >> However, what I do not agree with, is that this means, that there is no >> need for an extension of commons collections. I mean, then ASF could als= o >> stop developing tomcat, because there are clearly other application serv= ers >> out there, that provide all functionality that tomcat has and maybe more= . >> >> The FAQs on how to contribute just say "if you see something that can be >> improved, create a patch". And not "...that can be improved, but has not >> yet been implemented in some other library". >> If "not implementing functionality, that has been implemented elsewhere" >> is a common policy of commons or of commons collections, then I would >> recommend to put this in the FAQs on how to contribute (although I think= , >> that would be a very bad thing to do, as I pointed out above). >> >> Having all that said, I still think that linking Predicates to queries >> would be a real improvement for commons collections. And I still would l= ike >> to contribute the functionality somehow. I see your point, that extendin= g >> java base classes is not the best thing to do. But as I said: I am willi= ng >> to make what ever adjustment is required (also it seems to me, that this >> means re-writing the hole thing from scratch ;-) >> >> So, what do you think? >> Regards >> Benedikt >> >> =A0On Jan 15, 2012 3:59 AM, "Benedikt Ritter"> >>> =A0wrote: >>> >>> =A0Hi, >>>> >>>> I have written a small extension for java.util.ArrayList, that allows = for >>>> qerrying Lists using (generic) predicates. In addition to that, I adap= ted >>>> org.springframework.data.jpa.****domain.Specifications class as a util >>>> to >>>> link predicates to queries. Here is how it works: >>>> >>>> QueryableList =A0qList =3D new QueryableArrayList(= )****; >>>> qList.addAll(getCustomers()); >>>> qList.getAll(new Predicate() { >>>> >>>> =A0 =A0public boolean evaluate(Customer element) { >>>> =A0 =A0 =A0 =A0if (element.getLastName().****startsWith("B")) { >>>> =A0 =A0 =A0 =A0 =A0 =A0return true; >>>> =A0 =A0 =A0 =A0} else { >>>> =A0 =A0 =A0 =A0 =A0 =A0return false; >>>> =A0 =A0 =A0 =A0} >>>> =A0 =A0} >>>> }); >>>> >>>> This will give you a List containing all customers, that match the giv= en >>>> predicate. Using the Query class, we can link predicates via AND and O= R >>>> or >>>> simply neglect them (the next example assumes, that we have a static >>>> import >>>> of the not and where method and startsWith(String) and bornAfter(int) = are >>>> util methods, that return predicates): >>>> >>>> List =A0queryResult =3D qList.getAll(not(startsWith("****B")= )); >>>> queryResult =3D qList.getAll(where(startsWith(** >>>> **"B")).or(startsWith("C"))); >>>> queryResult =3D qList.getAll(where(startsWith(** >>>> **"B")).and(bornAfter(1980))); >>>> >>>> In addition to that, there are implementations of common collection >>>> methods using predicates: >>>> >>>> public boolean containsMatch(Predicate =A0predicate); >>>> public Iterator =A0matchIterator(Predicate =A0predicate); >>>> public boolean retainAllMatches(Predicate =A0predicate); >>>> public boolean removeAllMatches(Predicate =A0predicate); >>>> >>>> ...and common list methods: >>>> >>>> public int indexOfMatch(Predicate =A0predicate); >>>> public int lastIndexOfMatch(Predicate =A0predicate); >>>> >>>> I think QueryableCollections would fit nicely into commons collections= , >>>> because as far as I know, commons collections only offers you the >>>> opportunity to validate if all elements in a collection match a given >>>> predicate. There is no possibility to easily query for objects matchin= g >>>> some criteria. >>>> Having that said, I would like to contribute all source code of >>>> QueryableCollections. I am willing to make what ever changes are >>>> required. >>>> >>>> Here are some thinks that I think will need to be adjusted before >>>> contribution: >>>> - swtich from my generic Predicate implementation to >>>> org.apache.commons.****collections.Predicate, >>>> although I really would like to see generics in commons collections. I= t >>>> saves you all the instanceof statements. >>>> - As far as I can see commons collections does not extend classes from >>>> java.util.* but decorates them. As I said QueryableArrayList is an >>>> extension of ArrayList. If there is a general policy of not extending >>>> java >>>> base classes, this would have to be changed. >>>> - Re-Implement jUnit tests using jUnit 3.8.1 (instead of jUnit 4.1.0) >>>> - change licence agreement von LGPL to Apache License >>>> >>>> All source code (and example code) is available at github: >>>> HEAD: https://github.com/britter/****QueryableCollections >>>> >>>> > >>>> v0.1.0: https://github.com/britter/****QueryableCollections/tree/** >>>> stable-0.1.0>>> stable-0.1.0 >>>> > >>>> You can download a build from my blog: >>>> http://www.systemoutprintln.****de/wp-content/uploads/** >>>> collections-0.1.0.jar>>> content/uploads/collections-0.**1.0.jar >>>> > >>>> >>>> I'm really exited to hear what you guys think of QueryableCollections. >>>> Regards >>>> Benedikt Ritter >>>> >>>> ------------------------------****----------------------------** >>>> --**--------- >>>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apac**he.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