KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > iterators > AbstractEmptyIterator


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 org.apache.commons.collections.iterators;
17
18 import java.util.NoSuchElementException JavaDoc;
19
20 /**
21  * Provides an implementation of an empty iterator.
22  *
23  * @since Commons Collections 3.1
24  * @version $Revision: 1.2 $ $Date: 2004/05/26 20:57:43 $
25  *
26  * @author Stephen Colebourne
27  */

28 abstract class AbstractEmptyIterator {
29  
30     /**
31      * Constructor.
32      */

33     protected AbstractEmptyIterator() {
34         super();
35     }
36
37     public boolean hasNext() {
38         return false;
39     }
40
41     public Object JavaDoc next() {
42         throw new NoSuchElementException JavaDoc("Iterator contains no elements");
43     }
44
45     public boolean hasPrevious() {
46         return false;
47     }
48
49     public Object JavaDoc previous() {
50         throw new NoSuchElementException JavaDoc("Iterator contains no elements");
51     }
52
53     public int nextIndex() {
54         return 0;
55     }
56
57     public int previousIndex() {
58         return -1;
59     }
60
61     public void add(Object JavaDoc obj) {
62         throw new UnsupportedOperationException JavaDoc("add() not supported for empty Iterator");
63     }
64
65     public void set(Object JavaDoc obj) {
66         throw new IllegalStateException JavaDoc("Iterator contains no elements");
67     }
68
69     public void remove() {
70         throw new IllegalStateException JavaDoc("Iterator contains no elements");
71     }
72
73     public Object JavaDoc getKey() {
74         throw new IllegalStateException JavaDoc("Iterator contains no elements");
75     }
76
77     public Object JavaDoc getValue() {
78         throw new IllegalStateException JavaDoc("Iterator contains no elements");
79     }
80
81     public Object JavaDoc setValue(Object JavaDoc value) {
82         throw new IllegalStateException JavaDoc("Iterator contains no elements");
83     }
84
85     public void reset() {
86         // do nothing
87
}
88
89 }
90
Popular Tags