001 /* JAPI - (Yet another (hopefully) useful) Java API 002 * 003 * Copyright (C) 2004-2006 Christian Hujer 004 * 005 * This program is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU General Public License as 007 * published by the Free Software Foundation; either version 2 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, but 011 * WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License 016 * along with this program; if not, write to the Free Software 017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 018 * 02111-1307, USA. 019 */ 020 021 package net.sf.japi.util; 022 023 import java.util.Iterator; 024 import java.util.NoSuchElementException; 025 026 /** An iterator that never returns elements and thus is always empty. 027 * @author <a href="mailto:chris@riedquat.de">Christian Hujer</a> 028 */ 029 public class EmptyIterator<T> implements Iterator<T> { 030 031 /** Create an Empty Iterator. 032 * Please note that this class does not hold any state. 033 * The Constructor only exists for convenient Generics programming. 034 * It makes sense to store an empty iterator somewhere and reuse it, eventually even in a static final variable. 035 */ 036 public EmptyIterator() { 037 } 038 039 /** {@inheritDoc} */ 040 public boolean hasNext() { 041 return false; 042 } 043 044 /** {@inheritDoc} */ 045 public T next() throws NoSuchElementException { 046 throw new NoSuchElementException("No more elements"); 047 } 048 049 /** {@inheritDoc} */ 050 public void remove() { 051 throw new UnsupportedOperationException(); 052 } 053 054 } // class EmptyIterator