1 /* Taken 2008 from Limewire -project under the following terms:
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 package net.sf.eos.trie;
17
18 import java.util.Iterator;
19 import java.util.NoSuchElementException;
20
21
22 /**
23 * Provides an unmodifiable empty iterator. <code>EmptyIterator</code> always
24 * returns that there aren't any more items and throws a
25 * {@link NoSuchElementException} when attempting to move to the next item.
26 *
27 <pre>
28 try{
29 EmptyIterator ei = new EmptyIterator();
30 ei.next();
31 } catch (Exception e) {
32 System.out.println("Expected to get NoSuchElementException exception: " + e.toString());
33 }
34
35 Output:
36 Expected to get NoSuchElementException exception: java.util.NoSuchElementException
37 </pre>
38 */
39 public class EmptyIterator extends UnmodifiableIterator {
40 /** A constant EmptyIterator. */
41 public final static Iterator EMPTY_ITERATOR = new EmptyIterator();
42
43 @SuppressWarnings("unchecked")
44 public static <T> Iterator<T> emptyIterator() {
45 return EMPTY_ITERATOR;
46 }
47
48 // inherits javadoc comment
49 public boolean hasNext() {
50 return false;
51 }
52
53 // inherits javadoc comment
54 public Object next() {
55 throw new NoSuchElementException();
56 }
57 }