I have created an array (tab[]) of objects and now I need to filter and print via one of their fields (ex. print if ob.a>1 ). I created an Iterator interface, ArrayIterator that goes through all entries on list and Predicate interface. This is constructor of my FilteringIterator:
private final Iterator iterf;
private final Predicate pred;
public FilteringIterator(ArrayIterator i, Predicate predykat)
{
iterf=i;
pred=predykat;
iterf.first();
}
Method that prints every entry using my "basic" iterator looks like this:
public void printlist()
{
ArrayIterator itab =new ArrayIterator(lista);
for(itab.first();!itab.isDone(); itab.next())
{
Student stud=(Student)itab.current();
stud.show();
}
}
I also have a class that implements Predicate interface:
public interface Predicate
{
public boolean accept(Object ob);
}
How to use my FilteringIterator, when it requires Predicate, and I cannot create such object, as it's an interface?