litesoft
@ 938
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.core.util; import java.util.*; /** * An Iterator, of another wrapped Iterator, that will NOT return any null values.<p> * * @author George Smith * @version 1.0 31Aug2010 */ public final class NoNullsIterator<T> extends AbstractWrappingIterator<T> { private T mLastValue = null; /** * Construct an Iterator (by wrapping another Iterator) that will NOT return any null values.<p> * * @param pIterator the wrapped Iterator (!null). */ public NoNullsIterator( Iterator<T> pIterator ) throws NullPointerException { super( pIterator ); } /** * Returns true if the iteration has more elements. * * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/Util/Iterator.html#hasNext()">java.util.Iterator#hasNext()</a> */ @Override public boolean hasNext() { while ( mLastValue == null ) { if ( !super.hasNext() ) { return false; } mLastValue = super.next(); } return true; } /** * Returns the next element in the interation. * * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/Util/Iterator.html#next()">java.util.Iterator#next()</a> */ @Override public T next() { if ( !hasNext() ) { super.next(); // throw exception } T rv = mLastValue; mLastValue = null; return rv; } } |