package dk.itu.oop.lecture5; public abstract class FilterIterator implements OOPIterator { private OOPIterator inIterator; private Object nextElement; protected abstract boolean condition(Object obj); public FilterIterator(OOPIterator in){ inIterator = in; findNext(); } private void findNext(){ while (inIterator.hasNext() ){ nextElement = inIterator.next(); if ( condition(nextElement) ) return; } nextElement = null; } public boolean hasNext(){ return nextElement != null; } public Object next(){ Object returnMe = nextElement; findNext(); return returnMe; } public Object nextFanzy(){ try { return nextElement; }finally{ findNext(); } } public Object peek(){ return nextElement; } public OOPIterator cloneMe(){ try{ FilterIterator clone = (FilterIterator)super.clone(); clone.inIterator = inIterator.cloneMe(); return clone; }catch(CloneNotSupportedException shouldNotHappen){ throw new Error("Object claims not to be able to clone"); } } }