commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy Rouillier <guyr-...@burntmail.com>
Subject Determine if an object is in a list
Date Tue, 01 Dec 2009 03:37:06 GMT
I have a list of objects of class X.  X has a unique identifier property 
  P.  Given a value p, I want to see if the list contains an object 
where x.P = p.  Very simple, I ended up using a for loop to iterate over 
the objects in listX, breaking when I found the first occurrence.

Before doing that, however, I tried to find something in Commons that 
would do this for me.  The closest I could find was 
org.apache.commons.collections.CollectionUtils.find(java.util.Collection 
collection, Predicate predicate).  However, I couldn't find a simple 
PropertyPredicate that allowed me to say "look for objects whose 
property P is p".  That seems like one of the most obvious uses of find, 
so I believe I'm just not looking in the right place.

I'd appreciate a pointer to where I can find this.  Thanks.

-- 
Guy Rouillier

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message