org.jbind.util.collection
Class FilterIterator
java.lang.Object
org.jbind.util.collection.FilterIterator
- All Implemented Interfaces:
- java.util.Iterator
- public class FilterIterator
- extends java.lang.Object
- implements java.util.Iterator
Filters the objects of an iterator such that all returned objects obey
a condition.
Usage example: Filter an iteration of strings such that only strings with
a lenght greater than 3 are returned:
for (Iterator i = new FilterIterator(a.iterator(),
new FilterIterator.ICondition() {
public boolean evaluate(Object anObject) {
return ((String)anObject).length() > 3;
}
}); i.hasNext(); )
{
System.out.println(i.next());
}
- Author:
- Wachter
Nested Class Summary |
static interface |
FilterIterator.ICondition
Interface which must be implemented in order to decide wheter objects
should be included in the iteration or not. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
FilterIterator
public FilterIterator(java.util.Iterator anIterator,
FilterIterator.ICondition aCondition)
- Constructs a FilterIterator, i.e. an iterator which returns only
objects which obey a condition.
- Parameters:
anIterator
- The iterator that should be filtered.aCondition
- The condition to be checked.
next
public java.lang.Object next()
- Specified by:
next
in interface java.util.Iterator
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interface java.util.Iterator
remove
public void remove()
- Specified by:
remove
in interface java.util.Iterator