commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Neidhart (JIRA)" <>
Subject [jira] [Updated] (COLLECTIONS-442) A set of enhanced iterator classes donated by the Apache Jena project
Date Sun, 05 May 2013 21:10:16 GMT


Thomas Neidhart updated COLLECTIONS-442:


I have reworked the patch a bit, see the attached file. My rationale was as follows:

 * reuse existing code as much as possible
 * use real classes instead of interfaces to avoid problems with breaking compatibility when
extending later on

An example how to use the interface:

public class MyTest {

    public static void main(String[] args) {

        List<Integer> list = new ArrayList<Integer>();
        FluentIterator<String> it =
                          .dropIf(new Predicate<Integer>() {
                              public boolean evaluate(Integer object) {
                                  return object.intValue() < 2;
                          .mapWith(new Transformer<Integer, String>() {
                              public String transform(Integer input) {
                                  return "[" + String.valueOf(input.intValue()) + "]";

This prints

[[2], [3], [1], [2], [3], [2], [3]]

In the original patch, "andThen" behaved differently to the other composition methods in the
sense, that only andThen returned the same object. All the other methods returned a new object.

This could be error-prone when people do things like this:


in fact, the "andThen" will update "it", while "filterKeep" will return a new object and leave
"it" untouched. This is fine as long as you do method chaining but can lead to unexpected
errors or behavior in other cases. 

So I decided to be consistent and always return the same object. The only exception is the
"mapWith" method, which will always return a new object as the generic return type may change.

I am not completely happy with the class name, so if somebody has a better idea?

Any comments are welcome, if the API is accepted we can still include it for the upcoming
4.0-alpha1 which I plan to release in 1-2 weeks.
> A set of enhanced iterator classes donated by the Apache Jena project
> ---------------------------------------------------------------------
>                 Key: COLLECTIONS-442
>                 URL:
>             Project: Commons Collections
>          Issue Type: Improvement
>          Components: Iterator
>            Reporter: Claude Warren
>             Fix For: 4.0
>         Attachments: COLLECTIONS-442.tar.gz,
> A set of templated (Generic) iterators that add filtering, mapping, and conversion to
set or list collections.  Tests included.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message