KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > collections > _BaseList_IteratorImpl


1 /*
2  * $Id: _BaseList_IteratorImpl.java,v 1.1 2003/04/24 15:14:33 leomekenkamp Exp $
3  * This file is based on AbstractList.java from GNU Classpath. Quote:
4
5 AbstractList.java -- Abstract implementation of most of List
6 Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
7
8 This file is part of GNU Classpath.
9
10 GNU Classpath is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14
15 GNU Classpath is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GNU Classpath; see the file COPYING. If not, write to the
22 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 02111-1307 USA.
24
25 Linking this library statically or dynamically with other modules is
26 making a combined work based on this library. Thus, the terms and
27 conditions of the GNU General Public License cover the whole
28 combination.
29
30 As a special exception, the copyright holders of this library give you
31 permission to link this library with independent modules to produce an
32 executable, regardless of the license terms of these independent
33 modules, and to copy and distribute the resulting executable under
34 terms of your choice, provided that you also meet, for each linked
35 independent module, the terms and conditions of the license of that
36 module. An independent module is a module which is not derived from
37 or based on this library. If you modify this library, you may extend
38 this exception to your version of the library, but you are not
39 obligated to do so. If you do not wish to do so, delete this
40 exception statement from your version.
41
42  * end quote.
43  *
44  * This file is licenced under the same conditions as its original (GPL +
45  * "special exception").
46  */

47
48 package org.ozoneDB.collections;
49
50 import java.util.ConcurrentModificationException JavaDoc;
51 import java.util.NoSuchElementException JavaDoc;
52 import org.ozoneDB.OzoneObject;
53
54 /**
55  *
56  * @author leo
57  */

58 public class _BaseList_IteratorImpl extends OzoneObject implements OzoneIterator {
59
60     private BaseList owner;
61     private int pos = 0;
62     private int size = owner.size();
63     private int last = -1;
64     private int knownMod;
65
66
67     /** Creates a new instance of _BaseOzoneList_iterator */
68     public _BaseList_IteratorImpl(BaseList owner) {
69         this.owner = owner;
70         knownMod = owner._org_ozoneDB_getModCount();
71     }
72
73     // This will get inlined, since it is private.
74
private void checkMod() {
75         if (knownMod != owner._org_ozoneDB_getModCount()) {
76             throw new ConcurrentModificationException JavaDoc();
77         }
78     }
79
80     public boolean hasNext() {
81         checkMod();
82         return pos < size;
83     }
84
85     public Object JavaDoc next() {
86         checkMod();
87         if (pos == size) {
88             throw new NoSuchElementException JavaDoc();
89         }
90         last = pos;
91         return owner.get(pos++);
92     }
93
94     public void remove() {
95         checkMod();
96         if (last < 0) {
97             throw new IllegalStateException JavaDoc();
98         }
99         owner.remove(last);
100         pos--;
101         size--;
102         last = -1;
103         knownMod = owner._org_ozoneDB_getModCount();
104     }
105
106 }
Popular Tags