1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.collections15.iterators;
17
18 import java.util.NoSuchElementException;
19
20 /***
21 * Provides an implementation of an empty iterator.
22 *
23 * @since Commons Collections 3.1
24 * @version $Revision: 1.1 $ $Date: 2005/02/27 18:48:37 $
25 *
26 * @author Stephen Colebourne
27 * @author Mauro Franceschini
28 */
29 abstract class AbstractEmptyIterator<E> {
30
31 /***
32 * Constructor.
33 */
34 protected AbstractEmptyIterator() {
35 super();
36 }
37
38 public boolean hasNext() {
39 return false;
40 }
41
42 public E next() {
43 throw new NoSuchElementException("Iterator contains no elements");
44 }
45
46 public boolean hasPrevious() {
47 return false;
48 }
49
50 public E previous() {
51 throw new NoSuchElementException("Iterator contains no elements");
52 }
53
54 public int nextIndex() {
55 return 0;
56 }
57
58 public int previousIndex() {
59 return -1;
60 }
61
62 public void add(E obj) {
63 throw new UnsupportedOperationException("add() not supported for empty Iterator");
64 }
65
66 public void set(E obj) {
67 throw new IllegalStateException("Iterator contains no elements");
68 }
69
70 public void remove() {
71 throw new IllegalStateException("Iterator contains no elements");
72 }
73
74 public E getKey() {
75 throw new IllegalStateException("Iterator contains no elements");
76 }
77
78 public E getValue() {
79 throw new IllegalStateException("Iterator contains no elements");
80 }
81
82 public E setValue(E value) {
83 throw new IllegalStateException("Iterator contains no elements");
84 }
85
86 public void reset() {
87
88 }
89
90 }