1 |
/* Iterator.java -- Interface for iterating over collections |
/* Iterator.java -- Interface for iterating over collections |
2 |
Copyright (C) 1998 Free Software Foundation, Inc. |
Copyright (C) 1998, 2001 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
28 |
package java.util; |
package java.util; |
29 |
|
|
30 |
/** |
/** |
31 |
* An object which iterates over a collection. An Iterator is used to return the |
* An object which iterates over a collection. An Iterator is used to return |
32 |
* items once only, in sequence, by successive calls to the next method. It is |
* the items once only, in sequence, by successive calls to the next method. |
33 |
* also possible to remove elements from the underlying collection by using the |
* It is also possible to remove elements from the underlying collection by |
34 |
* optional remove method. Iterator is intended as a replacement for the |
* using the optional remove method. Iterator is intended as a replacement |
35 |
* Enumeration interface of previous versions of Java, which did not have the |
* for the Enumeration interface of previous versions of Java, which did not |
36 |
* remove method and had less conveniently named methods. |
* have the remove method and had less conveniently named methods. |
37 |
|
* |
38 |
|
* @author Original author unknown |
39 |
|
* @author Eric Blake <ebb9@email.byu.edu> |
40 |
|
* @see Collection |
41 |
|
* @see ListIterator |
42 |
|
* @see Enumeration |
43 |
|
* @since 1.2 |
44 |
|
* @status updated to 1.4 |
45 |
*/ |
*/ |
46 |
public interface Iterator |
public interface Iterator |
47 |
{ |
{ |
48 |
/** |
/** |
49 |
* Tests whether there are elements remaining in the collection. |
* Tests whether there are elements remaining in the collection. In other |
50 |
|
* words, calling <code>next()</code> will not throw an exception. |
51 |
* |
* |
52 |
* @return true if there is at least one more element in the collection, |
* @return true if there is at least one more element in the collection |
|
* that is, if the next call to next will not throw NoSuchElementException. |
|
53 |
*/ |
*/ |
54 |
boolean hasNext(); |
boolean hasNext(); |
55 |
|
|
57 |
* Obtain the next element in the collection. |
* Obtain the next element in the collection. |
58 |
* |
* |
59 |
* @return the next element in the collection |
* @return the next element in the collection |
60 |
* @exception NoSuchElementException if there are no more elements |
* @throws NoSuchElementException if there are no more elements |
61 |
*/ |
*/ |
62 |
Object next(); |
Object next(); |
63 |
|
|
64 |
/** |
/** |
65 |
* Remove from the underlying collection the last element returned by next. |
* Remove from the underlying collection the last element returned by next |
66 |
* This method can be called only once after each call to next. It does not |
* (optional operation). This method can be called only once after each |
67 |
* affect what will be returned by subsequent calls to next. This operation is |
* call to <code>next()</code>. It does not affect what will be returned |
68 |
* optional, it may throw an UnsupportedOperationException. |
* by subsequent calls to next. |
69 |
* |
* |
70 |
* @exception IllegalStateException if next has not yet been called or remove |
* @throws IllegalStateException if next has not yet been called or remove |
71 |
* has already been called since the last call to next. |
* has already been called since the last call to next. |
72 |
* @exception UnsupportedOperationException if this Iterator does not support |
* @throws UnsupportedOperationException if this Iterator does not support |
73 |
* the remove operation. |
* the remove operation. |
74 |
*/ |
*/ |
75 |
void remove(); |
void remove(); |
76 |
} |
} |