Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt
package org.litesoft.core.util;

import java.util.*;

/**
 * There are two points for having this class:<p>
 * <p/>
 * First, that all Iterators need to be able to throw NoSuchElementException if
 * next is inappropriately called.  The easiest way is to simply implement a
 * dumb next at a superclass level that always throws it.<p>
 * <p/>
 * Second, the SUN/Java Iterators should NOT have supported <i>remove()</i>.
 * The GOF (Gang Of Four) Iterator not only provided more funcationality
 * (supporting both multiple reads of the current item AND the ability to pass
 * over the collection multiple times), but provided a nice <i>read only</i>
 * view of an arbitrarily stored collection.  To <i>restore</i> the read only
 * view aspect of an Iterator, this class provides a <i>final</i> implimentation
 * of <i>remove()</i>.<p>
 *
 * @author George Smith
 * @version 1.0 7/28/01
 * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/Util/Iterator.html">java.util.Iterator</a>
 */

public abstract class AbstractReadOnlyIterator<T> implements Iterator<T>,
                                                             Disposable
{
    /**
     * hasNext() is part of the Iterator interface.  It is abtract here
     * because there is no reasonable, common, implementation and to
     * remind the developer who extends this class that they, at a
     * minimum, need to implement it.<p>
     *
     * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/Util/Iterator.html#hasNext()">java.util.Iterator#hasNext()</a>
     */
    @Override
    abstract public boolean hasNext();

    /**
     * All most all Iterators will need to throw NoSuchElementException
     * at some point, so this is simply a convenience implementation.<p>
     *
     * @throws NoSuchElementException
     * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/Util/Iterator.html#next()">java.util.Iterator#next()</a>
     */
    @Override
    public T next()
    {
        throw new NoSuchElementException();
    }

    /**
     * As mentioned above, the SUN/Java Iterators should NOT have supported
     * <i>remove()</i>.<p>
     * <p/>
     * Therefor, this method is a <i>final</i> version that throws
     * UnsupportedOperationException.<p>
     *
     * @throws UnsupportedOperationException
     * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/Util/Iterator.html#remove()">java.util.Iterator.remove()</a>
     */
    @Override
    public final void remove()
    {
        throw new UnsupportedOperationException();
    }

    @Override
    public void dispose()
    {
    }
}

Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/core/util/AbstractReadOnlyIterator.java

Diff revisions: vs.
Revision Author Commited Message
50 Diff Diff GeorgeS picture GeorgeS Tue 13 Apr, 2010 11:51:38 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000