org.apache.commons.collections.iterators

Class FilterIterator

Implemented Interfaces:
Iterator
Known Direct Subclasses:
FilterIterator, UniqueFilterIterator

public class FilterIterator
extends ProxyIterator

A Proxy Iterator which takes a Predicate instance to filter out objects from an underlying Iterator instance. Only objects for which the specified Predicate evaluates to true are returned.
Authors:
James Strachan
Jan Sorensen
Since:
1.0

Constructor Summary

FilterIterator()
Constructs a new FilterIterator that will not function until setIterator is invoked.
FilterIterator(Iterator iterator)
Constructs a new FilterIterator that will not function until setPredicate is invoked.
FilterIterator(Iterator iterator, Predicate predicate)
Constructs a new FilterIterator that will use the given iterator and predicate.

Method Summary

Predicate
getPredicate()
Getter for property predicate.
boolean
hasNext()
Returns true if the underlying iterator contains an object that matches the predicate.
Object
next()
Returns the next object that matches the predicate.
void
remove()
Always throws UnsupportedOperationException as this class does look-ahead with its internal iterator.
void
setPredicate(Predicate predicate)
Setter for property predicate.

Methods inherited from class org.apache.commons.collections.iterators.ProxyIterator

getIterator, hasNext, next, remove, setIterator

Constructor Details

FilterIterator

public FilterIterator()

FilterIterator

public FilterIterator(Iterator iterator)
Parameters:
iterator - the iterator to use

FilterIterator

public FilterIterator(Iterator iterator,
                      Predicate predicate)
Constructs a new FilterIterator that will use the given iterator and predicate.
Parameters:
iterator - the iterator to use
predicate - the predicate to use

Method Details

getPredicate

public Predicate getPredicate()
Getter for property predicate.
Returns:
Value of property predicate.

hasNext

public boolean hasNext()
Returns true if the underlying iterator contains an object that matches the predicate.
Overrides:
hasNext in interface ProxyIterator
Returns:
true if there is another object that matches the predicate

next

public Object next()
Returns the next object that matches the predicate.
Overrides:
next in interface ProxyIterator
Returns:
the next object which matches the given predicate

remove

public void remove()
Always throws UnsupportedOperationException as this class does look-ahead with its internal iterator.
Overrides:
remove in interface ProxyIterator

setPredicate

public void setPredicate(Predicate predicate)
Setter for property predicate.
Parameters:
predicate - New value of property predicate.

Copyright © 2001-2004 Apache Software Foundation. Documenation generated ${TODAY}.