commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Moritz Petersen <moritzpeter...@mac.com>
Subject [collections] ListUtils.predicatedList() throws IllegalArgumentException
Date Sat, 26 Oct 2002 11:18:59 GMT
Hi, am I getting it wrong? I want to create a predicatedList, my code  
is like this:

             predicatedList = ListUtils.predicatedList(list, new  
MyPredicate());

The list already contains some elements.
I would expect, that the predicatedList is some sort of a filtered List  
of my original list. MyPredicate.evaluate() returns true or false,  
which I believe is the expected behaviour. true, if the object should  
appear in the predicatedList and false if it doesn't.
But the following exception is thrown:

java.lang.IllegalArgumentException: Cannot add Object - Predicate  
rejected it
	at  
org.apache.commons.collections.CollectionUtils$PredicatedCollection.vali 
date(CollectionUtils.java:862)
	at  
org.apache.commons.collections.CollectionUtils$PredicatedCollection.<ini 
t>(CollectionUtils.java:844)
	at  
org.apache.commons.collections.ListUtils$PredicatedList.<init>(ListUtils 
.java:218)
	at  
org.apache.commons.collections.ListUtils.predicatedList(ListUtils.java:4 
59)
	at TableDataSource.setFilter(TableDataSource.java:79)
	at Controller.search(Controller.java:78)

The affected code in CollectionUtils is:

         protected void validate(Object o) {
             if (!predicate.evaluate(o)) {
                 throw new IllegalArgumentException("Cannot add Object -  
Predicate rejected it");
             }
         }

which makes me wonder why this validation should throw an exception and  
not just return true or false. So I believe I haven't understood how  
Predicates work. Looking at the test cases, don't make the situation  
more clear to me, because there are some "BlukTests" used, which make  
the testing process cryptic. Usually I can learn a lot by looking at  
test cases, but in this case, I don't see how the predicatedList()  
method is completely tested at all. Any explanations are highly  
appreciated. Thank you,

-Mo.


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message