net.sf.staccatocommons.collections.internal.iterator.TakeWhileIterator Maven / Gradle / Ivy
/**
* Copyright (c) 2011, The Staccato-Commons Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/
package net.sf.staccatocommons.collections.internal.iterator;
import java.util.Iterator;
import net.sf.staccatocommons.defs.Evaluable;
import net.sf.staccatocommons.iterators.NextGetIterator;
/**
* @author flbulgarelli
*
*/
public final class TakeWhileIterator extends NextGetIterator {
private final Evaluable predicate;
private final Iterator iter;
/**
* Creates a new {@link TakeWhileIterator}
*/
public TakeWhileIterator(Iterator iter, Evaluable predicate) {
this.predicate = predicate;
this.iter = iter;
}
@Override
protected boolean updateNext() {
return iter.hasNext() && predicate.eval(setNext(iter.next()));
}
}