KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portlet > forums > helper > IndexIterator


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Forums JBoss Portlet *
6  * *
7  * Distributable under GPL license. *
8  * See terms of license at gnu.org. *
9  * *
10  *****************************************/

11 package org.jboss.portlet.forums.helper;
12
13 import java.util.Iterator JavaDoc;
14
15 /**
16  * An iterator wrapper than keeps track of the index.
17  *
18  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
19  * @version $Revision: 1.1.1.1 $
20  */

21 public class IndexIterator
22    implements Iterator JavaDoc
23 {
24    private int index;
25    private Iterator JavaDoc iterator;
26
27    /**
28     * Creates a new {@link IndexIterator} object.
29     *
30     * @param iterator DOCUMENT_ME
31     */

32    public IndexIterator(Iterator JavaDoc iterator)
33    {
34       this(iterator, 0);
35    }
36
37    /**
38     * Creates a new {@link IndexIterator} object.
39     *
40     * @param iterator DOCUMENT_ME
41     * @param start DOCUMENT_ME
42     */

43    public IndexIterator(Iterator JavaDoc iterator,
44                         int start)
45    {
46       this.iterator = iterator;
47       this.index = start;
48    }
49
50    /**
51     * DOCUMENT_ME
52     *
53     * @return DOCUMENT_ME
54     */

55    public boolean hasNext()
56    {
57       return iterator.hasNext();
58    }
59
60    /**
61     * DOCUMENT_ME
62     *
63     * @return DOCUMENT_ME
64     */

65    public Object JavaDoc next()
66    {
67       index++;
68       return iterator.next();
69    }
70
71    /**
72     * DOCUMENT_ME
73     */

74    public void remove()
75    {
76       iterator.remove();
77    }
78
79    /**
80     * DOCUMENT_ME
81     *
82     * @return DOCUMENT_ME
83     */

84    public int getIndex()
85    {
86       return index;
87    }
88
89    /**
90     * DOCUMENT_ME
91     *
92     * @param iterator DOCUMENT_ME
93     *
94     * @return DOCUMENT_ME
95     */

96    public static IndexIterator wrap(Iterator JavaDoc iterator)
97    {
98       return new IndexIterator(iterator);
99    }
100
101    /**
102     * DOCUMENT_ME
103     *
104     * @param iterator DOCUMENT_ME
105     * @param start DOCUMENT_ME
106     *
107     * @return DOCUMENT_ME
108     */

109    public static IndexIterator wrap(Iterator JavaDoc iterator,
110                                     int start)
111    {
112       return new IndexIterator(iterator, start);
113    }
114 }
Popular Tags