KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: _BaseList_SubList_listIterator.java,v 1.1 2003/10/02 09:01:39 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.NoSuchElementException JavaDoc;
51 import org.ozoneDB.OzoneObject;
52
53 /**
54  * @author Original author unknown
55  * @author Eric Blake <ebb9@email.byu.edu>
56  * @author ported to Ozone by Leo Mekenkamp
57  */

58 public class _BaseList_SubList_listIterator extends OzoneObject implements OzoneListIterator {
59
60     private _BaseList_SubList subList;
61     private OzoneListIterator wrapped;
62
63     private int position;
64
65     public _BaseList_SubList_listIterator(_BaseList_SubList subList, OzoneListIterator wrapped) {
66         this.subList = subList;
67         this.wrapped = wrapped;
68         position = wrapped.nextIndex();
69     }
70
71     public boolean hasNext() {
72         subList._org_ozoneDB_checkMod();
73         return position < subList.size();
74     }
75
76     public boolean hasPrevious() {
77         subList._org_ozoneDB_checkMod();
78         return position > 0;
79     }
80
81     public Object JavaDoc next() {
82         if (position >= subList.size()) {
83             throw new NoSuchElementException JavaDoc();
84         }
85         position++;
86         return wrapped.next();
87     }
88
89     public Object JavaDoc previous() {
90         if (position <= 0) {
91             throw new NoSuchElementException JavaDoc();
92         }
93         position--;
94         return wrapped.previous();
95     }
96
97     public int nextIndex() {
98         return wrapped.nextIndex() - subList._org_ozoneDB_getOffset();
99     }
100
101     public int previousIndex() {
102         return wrapped.previousIndex() - subList._org_ozoneDB_getOffset();
103     }
104
105     public void remove() {
106         wrapped.remove();
107         subList._org_ozoneDB_incSize(-1);
108         position = nextIndex();
109         subList._org_ozoneDB_syncModCountWithBackingList();
110     }
111
112     public void set(Object JavaDoc o) {
113         wrapped.set(o);
114     }
115
116     public void add(Object JavaDoc o) {
117         wrapped.add(o);
118         subList._org_ozoneDB_incSize(1);
119         position++;
120         subList._org_ozoneDB_syncModCountWithBackingList();
121     }
122
123     // Here is the reason why the various modCount fields are mostly
124
// ignored in this wrapper listIterator.
125
// If the backing listIterator is failfast, then the following holds:
126
// Using any other method on this list will call a corresponding
127
// method on the backing list *after* the backing listIterator
128
// is created, which will in turn cause a ConcurrentModException
129
// when this listIterator comes to use the backing one. So it is
130
// implicitly failfast.
131
// If the backing listIterator is NOT failfast, then the whole of
132
// this list isn't failfast, because the modCount field of the
133
// backing list is not valid. It would still be *possible* to
134
// make the iterator failfast wrt modifications of the sublist
135
// only, but somewhat pointless when the list can be changed under
136
// us.
137
// Either way, no explicit handling of modCount is needed.
138
// However modCount = backingList.modCount must be executed in add
139
// and remove, and size must also be updated in these two methods,
140
// since they do not go through the corresponding methods of the subList.
141
}
142
Popular Tags