00001 package ca.mcgill.sable.util;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 public abstract class AbstractList extends AbstractCollection implements List
00070 {
00071 protected transient int modCount;
00072
00073 private class AbstractListIterator implements ListIterator
00074 {
00075 private int index = 0;
00076 private int lastIndex = -1;
00077 private int localModCount = modCount;
00078
00079 AbstractListIterator(int index)
00080 {
00081 this.index = index;
00082 }
00083
00084 public void set(Object o)
00085 {
00086 if(localModCount != modCount)
00087 {
00088 throw new ConcurrentModificationException();
00089 }
00090
00091 if(lastIndex == -1)
00092 {
00093 throw new java.util.NoSuchElementException();
00094 }
00095
00096 AbstractList.this.set(lastIndex, o);
00097 }
00098
00099 public void add(Object o)
00100 {
00101 if(localModCount != modCount)
00102 {
00103 throw new ConcurrentModificationException();
00104 }
00105
00106 AbstractList.this.add(index, o);
00107 localModCount = modCount;
00108 }
00109
00110 public int nextIndex()
00111 {
00112 if(localModCount != modCount)
00113 {
00114 throw new ConcurrentModificationException();
00115 }
00116
00117 return index;
00118 }
00119
00120 public int previousIndex()
00121 {
00122 if(localModCount != modCount)
00123 {
00124 throw new ConcurrentModificationException();
00125 }
00126
00127 return index - 1;
00128 }
00129
00130 public boolean hasPrevious()
00131 {
00132 if(localModCount != modCount)
00133 {
00134 throw new ConcurrentModificationException();
00135 }
00136
00137 return index > 0;
00138 }
00139
00140 public Object previous()
00141 {
00142 if(localModCount != modCount)
00143 {
00144 throw new ConcurrentModificationException();
00145 }
00146
00147 lastIndex = --index;
00148 return get(index);
00149 }
00150
00151 public boolean hasNext()
00152 {
00153 if(localModCount != modCount)
00154 {
00155 throw new ConcurrentModificationException();
00156 }
00157
00158 return index < size();
00159 }
00160
00161 public Object next()
00162 {
00163 if(localModCount != modCount)
00164 {
00165 throw new ConcurrentModificationException();
00166 }
00167
00168 lastIndex = index;
00169 return get(index++);
00170 }
00171
00172 public void remove()
00173 {
00174 if(localModCount != modCount)
00175 {
00176 throw new ConcurrentModificationException();
00177 }
00178
00179 if(lastIndex == -1)
00180 {
00181 throw new java.util.NoSuchElementException();
00182 }
00183
00184 if(lastIndex != index)
00185 {
00186 index = lastIndex;
00187 }
00188
00189 AbstractList.this.remove(lastIndex);
00190 localModCount = modCount;
00191 lastIndex = -1;
00192 }
00193 }
00194 public void add(int index, Object element)
00195 {
00196 throw new UnsupportedOperationException();
00197 }
00198 public boolean add(Object o)
00199 {
00200 add(size(), o);
00201 return true;
00202 }
00203 public boolean addAll(int index, Collection c)
00204 {
00205 boolean modified = false;
00206
00207 for(Iterator i = c.iterator(); i.hasNext();)
00208 {
00209 add(index++, i.next());
00210 modified = true;
00211 }
00212
00213 return modified;
00214 }
00215 public boolean equals(Object o)
00216 {
00217 if(o == this)
00218 {
00219 return true;
00220 }
00221
00222 if(!(o instanceof List))
00223 {
00224 return false;
00225 }
00226
00227 List list = (List) o;
00228
00229 Iterator j = list.iterator();
00230 for(Iterator i = iterator(); i.hasNext();)
00231 {
00232 if(!j.hasNext())
00233 {
00234 return false;
00235 }
00236
00237 if(!i.next().equals(j.next()))
00238 {
00239 return false;
00240 }
00241 }
00242
00243 if(j.hasNext())
00244 {
00245 return false;
00246 }
00247
00248 return true;
00249 }
00250 public int hashCode()
00251 {
00252 int hashCode = 0;
00253
00254 Iterator i = iterator();
00255
00256 while(i.hasNext())
00257 {
00258 Object obj = i.next();
00259 hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
00260 }
00261
00262 return hashCode;
00263 }
00264 public int indexOf(Object o)
00265 {
00266 if(size() == 0)
00267 {
00268 return -1;
00269 }
00270
00271 return indexOf(o, 0);
00272 }
00273 public int indexOf(Object o, int index)
00274 {
00275 ListIterator i = listIterator(index);
00276 do
00277 {
00278 if(o == null ? i.next() == null : o.equals(i.next()))
00279 {
00280 return i.previousIndex();
00281 }
00282 }
00283 while(i.hasNext());
00284
00285 return -1;
00286 }
00287 public Iterator iterator()
00288 {
00289 return listIterator();
00290 }
00291 public int lastIndexOf(Object o)
00292 {
00293 int size = size();
00294
00295 if(size == 0)
00296 {
00297 return -1;
00298 }
00299
00300 return lastIndexOf(o, size - 1);
00301 }
00302 public int lastIndexOf(Object o, int index)
00303 {
00304 for(ListIterator i = listIterator(index + 1); i.hasPrevious();)
00305 {
00306 if(o == null ? i.previous() == null : o.equals(i.previous()))
00307 {
00308 return i.nextIndex();
00309 }
00310 }
00311
00312 return -1;
00313 }
00314 public ListIterator listIterator()
00315 {
00316 return listIterator(0);
00317 }
00318 public ListIterator listIterator(int index)
00319 {
00320 return new AbstractListIterator(index);
00321 }
00322 public Object remove(int index)
00323 {
00324 throw new UnsupportedOperationException();
00325 }
00326 public void removeRange(int fromIndex, int toIndex)
00327 {
00328 int size = size();
00329
00330 if(fromIndex < 0 || fromIndex >= size || toIndex > size || toIndex < fromIndex)
00331 {
00332 throw new ArrayIndexOutOfBoundsException();
00333 }
00334
00335 int count = toIndex - fromIndex;
00336
00337 for(int i = 0; i < count; i++)
00338 {
00339 remove(fromIndex);
00340 }
00341 }
00342 public Object set(int index, Object element)
00343 {
00344 throw new UnsupportedOperationException();
00345 }
00346 }