View Javadoc

1   /*
2    *  Copyright 2004 The Apache Software Foundation
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
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          // do nothing
88      }
89  
90  }