1 | package org.farng.mp3.filename; |
2 | |
3 | import java.util.Iterator; |
4 | import java.util.NoSuchElementException; |
5 | |
6 | /** |
7 | * This class is an iterator for the <code>FilenameToken</code> class. |
8 | * |
9 | * @author Eric Farng |
10 | * @version $Revision: 1.1 $ |
11 | */ |
12 | public class FilenameTokenIterator implements Iterator { |
13 | |
14 | /** |
15 | * Token class that this iterator is for |
16 | */ |
17 | private FilenameToken filenameToken; |
18 | /** |
19 | * if true, then the token has already been returned and this iterator is done |
20 | */ |
21 | private boolean returnedToken = false; |
22 | |
23 | /** |
24 | * Creates a new FilenameTokenIterator object. |
25 | * |
26 | * @param filenameToken <code>FilenameToken</code> class that this iterator will iterate through. |
27 | */ |
28 | public FilenameTokenIterator(final FilenameToken filenameToken) { |
29 | super(); |
30 | this.filenameToken = filenameToken; |
31 | } |
32 | |
33 | /** |
34 | * Returns true if the iteration has more elements. (In other words, returns true if next would return an element |
35 | * rather than throwing an exception.) |
36 | * |
37 | * @return true if the iteration has more elements |
38 | */ |
39 | public boolean hasNext() { |
40 | return !returnedToken; |
41 | } |
42 | |
43 | /** |
44 | * Returns the next element in the iteration. |
45 | * |
46 | * @return the next element in the iteration. |
47 | */ |
48 | public Object next() { |
49 | if (!returnedToken) { |
50 | returnedToken = true; |
51 | return filenameToken; |
52 | } |
53 | throw new NoSuchElementException("Iteration has no more elements."); |
54 | } |
55 | |
56 | /** |
57 | * This method is not supported in this iterator. |
58 | * |
59 | * @throws UnsupportedOperationException This method is not supported in this iterator |
60 | */ |
61 | public void remove() { |
62 | //todo Implement this java.util.Iterator method |
63 | throw new UnsupportedOperationException("Method remove() not yet implemented."); |
64 | } |
65 | } |