commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rich Dougherty" <r...@rd.gen.nz>
Subject Re: [collections][patch] ClassFilterIterator
Date Tue, 10 Dec 2002 19:47:55 GMT
> Hi, here is a suggested addition to the collections component. This is a
>  trivial FilterIterator which only returns objects of a given class. I
> attached the class with its associated test case.

Hi Emmanuel

Thanks for the contribution.

If I've got this right, ClassFilterIterator alters the behaviour of
FilterIterator to filter its objects by their class. In this case it feels
to me that using a subclass might be a bit too heavy since
ClassFilterIterator isn't really altering FilterIterator's behaviour, it
is just supplying a default value for its predicate.

In other words, instead of

  Iterator classFilterIterator =
      new ClassFilterIterator(iterator, String.class);

why not

  Iterator classFilterIterator =
      new FilterIterator(iterator, new ClassPredicate(String.class));

To me, the second example seems like the easiest and most transparent way
to filter classes by their class. Perhaps you could extract the inner
class and submit that separately? (Although I'm not sure where you submit
it: collections, lang or functors?)

Actually, I've got one more comment. Not a biggie, but since I'm already
here. :-) The constructor of ClassPredicate interprets a null value as
equivalent to Object.class. It might be a good idea to shy away from
default behaviour, and instead throw a NullPointerException.

My rationale is this: if a developer wanted to get all classes they should
use Object.class or an always-true Predicate or not filter the values at
all. To me, all these approaches seem a lot clearer.

Rich



--
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