tango.util.collection.iterator.FilteringIterator

class FilteringIterator(T) : Iterator!(T) #
FilteringIterators allow you to filter out elements from other enumerations before they are seen by their `consumers' (i.e., the callers of `get').
FilteringIterators work as wrappers around other Iterators. To build one, you need an existing Iterator (perhaps one from coll.elements(), for some Collection coll), and a Predicate object (i.e., implementing interface Predicate). For example, if you want to screen out everything but Panel objects from a collection coll that might hold things other than Panels, write something of the form:
1
2
3
4
Iterator e = coll.elements();
Iterator panels = FilteringIterator(e, IsPanel);
while (panels.more())
 doSomethingWith(cast(Panel)(panels.get()));
To use this, you will also need to write a little class of the form:
1
2
3
class IsPanel : Predicate {
 bool predicate(Object v) { return cast(Panel) v !is null; }
}

See Also:

tango.util.collection.Predicate.predicate

Author:

Doug Lea
Iterator!(T) src_ [private] #
The enumeration we are wrapping
Predicate pred_ [private] #
The screening predicate
bool sign_ [private] #
The sense of the predicate. False means to invert
T get_ [private] #
The next element to hand out
bool haveNext_ [private] #
True if we have a next element
this(Iterator!(T) src, Predicate p) [public] #
Make a Filter using src for the elements, and p as the screener, selecting only those elements of src for which p is true
this(Iterator!(T) src, Predicate p, bool sense) [public] #
Make a Filter using src for the elements, and p as the screener, selecting only those elements of src for which p.predicate(v) == sense. A value of true for sense selects only values for which p.predicate is true. A value of false selects only those for which it is false.
bool more() [public, final] #
Implements tango.util.collection.model.Iterator.more
T get() [public, final] #
Implements tango.util.collection.model.Iterator.get.
void findNext() [private, final] #
Traverse through src_ elements finding one passing predicate