View Javadoc

    1   /**
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package net.sourceforge.pmd.util;
    5
    6   import java.util.Iterator;
    7
    8   /**
    9    * A singleton iterator that never has anything.
    10   *
    11   * @author Brian Remedios
    12   *
    13   * @param <T>
    14   */
    15  public class EmptyIterator<T extends Object> implements Iterator<T> {
    16
    17      	@SuppressWarnings("rawtypes")
    18  	public static final Iterator instance = new EmptyIterator();
    19
    20      	@SuppressWarnings("unchecked")
    21  	public static final <T extends Object> Iterator<T> instance() {
    22      	    return instance;
    23      	}
    24
    25  	private EmptyIterator() {}
    26
    27  	public boolean hasNext() { return false; }
    28
    29  	public T next() { return null;	}
    30
    31  	public void remove() {
    32  		throw new UnsupportedOperationException();
    33  	}
    34  }