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 64 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.core.util; import java.util.*; /** * An Iterator that implements the Null Object pattern.<p> * <p/> * This class is not directly instantiable as it is implemented with the * singleton pattern.<p> * <p/> * This class <i>fully</i> implements the java.util.Iterator interface, but * always indicates that there are no more elements.<p> * * @author George Smith * @version 1.0 7/28/01 */ public final class NullIterator<T> extends AbstractReadOnlyIterator<T> { /** * Get the single instance of the Iterator.<p> * * @return the NullIterator instance. */ @SuppressWarnings({"unchecked"}) public static <V> Iterator<V> getInstance() { return (Iterator<V>) INSTANCE; } private static final Iterator INSTANCE = new NullIterator(); private NullIterator() { } /** * Returns <tt>false</tt>, because there is <b>never</b> another element.<p> * <p/> * Note: <tt>next</tt> will throw an exception.<p> * * @return <tt>false</tt>.<p> * * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/Util/Iterator.html#hasNext()">java.util.Iterator#hasNext()</a> * @see AbstractReadOnlyIterator#next() */ @Override public boolean hasNext() { return false; } /** * Returns a debug/human friendly String that represents this.<p> * * @return A String representation of this. */ @Override public String toString() { return "NullIterator"; } } |