Spliterator.tryAdvance
Remi Forax
forax at univ-mlv.fr
Mon Feb 11 07:34:56 PST 2013
There is another point,
the specification should be relatex to allow tryAdvance to not always
call the consumer taken as parameter.
If by example, I want to implements a Spliterator that filter the elements,
this implementation should be legal:
class FilterSpliterator implements Spliterator {
private final Spliterator spliterator;
private final Predicate predicate;
public FilterSpliterator(Spliterator spliterator, Predicate predicate) {
....
}
public void tryAdvance(Consumer consumer) {
spliterator.tryAdvance(element -> {
if (predicate.test(element)) {
consumer.accept(element);
}
});
}
}
otherwise, you have to use a while loop around spliterator.tryAdvance but
because there is no way to transmit the information that the element is
accepted or not
(see my previous mail), you can not use a lambda here and you have to
rely on an inner class.
cheers,
Rémi
More information about the lambda-libs-spec-observers
mailing list