1 47 48 package org.ozoneDB.collections; 49 50 import java.util.Collection ; 51 import java.util.ConcurrentModificationException ; 52 import java.util.Iterator ; 53 import java.util.List ; 54 import java.util.ListIterator ; 55 import java.util.RandomAccess ; 56 57 87 public abstract class BaseListImpl extends AbstractOzoneCollection implements BaseList { 88 89 104 protected int modCount; 105 106 109 protected BaseListImpl() { 110 } 111 112 public void add(int index, Object o) { 113 throw new UnsupportedOperationException (); 114 } 115 116 132 public boolean add(Object o) { 133 add(size(), o); 134 return true; 135 } 136 137 public boolean addAll(int index, Collection c) { 138 Iterator itr = c.iterator(); 139 int size = c.size(); 140 for (int pos = size; pos > 0; pos--) 141 add(index++, itr.next()); 142 return size > 0; 143 } 144 145 156 public void clear() { 157 _org_ozoneDB_removeRange(0, size()); 158 } 159 160 179 public boolean equals(Object o) { 180 if (o == this) 181 return true; 182 if (! (o instanceof List )) 183 return false; 184 int size = size(); 185 if (size != ((List ) o).size()) 186 return false; 187 188 Iterator itr1 = iterator(); 189 Iterator itr2 = ((List ) o).iterator(); 190 191 while (--size >= 0) 192 if (! equals(itr1.next(), itr2.next())) 193 return false; 194 return true; 195 } 196 197 217 public int hashCode() { 218 int hashCode = 1; 219 Iterator itr = iterator(); 220 int pos = size(); 221 while (--pos >= 0) 222 hashCode = 31 * hashCode + hashCode(itr.next()); 223 return hashCode; 224 } 225 226 public int indexOf(Object o) { 227 ListIterator itr = listIterator(); 228 int size = size(); 229 for (int pos = 0; pos < size; pos++) 230 if (equals(o, itr.next())) 231 return pos; 232 return -1; 233 } 234 235 247 public Iterator iterator() { 248 return (Iterator ) database().createObject(_BaseList_IteratorImpl.class.getName(), 251 BaseList.class.getName(), 252 new Object [] {self()}); 253 } 254 255 256 257 265 public int lastIndexOf(Object o) { 266 int pos = size(); 267 ListIterator itr = listIterator(pos); 268 while (--pos >= 0) 269 if (equals(o, itr.previous())) 270 return pos; 271 return -1; 272 } 273 274 281 public ListIterator listIterator() { 282 return listIterator(0); 283 } 284 285 303 public ListIterator listIterator(final int index) { 304 if (index < 0 || index > size()) { 305 throw new IndexOutOfBoundsException ("Index: " + index + ", Size:" 306 + size()); 307 } 308 return (ListIterator ) database().createObject(_BaseList_ListIteratorImpl.class, 310 new Class [] {BaseList.class, int.class}, 311 new Object [] {self(), new Integer (index)}); 312 } 313 314 328 public Object remove(int index) { 329 throw new UnsupportedOperationException (); 330 } 331 332 349 public void _org_ozoneDB_removeRange(int fromIndex, int toIndex) { 350 ListIterator itr = listIterator(fromIndex); 351 for (int index = fromIndex; index < toIndex; index++) { 352 itr.next(); 353 itr.remove(); 354 } 355 } 356 357 372 public Object set(int index, Object o) { 373 throw new UnsupportedOperationException (); 374 } 375 376 420 public List subList(int fromIndex, int toIndex) { 421 if (fromIndex > toIndex) 424 throw new IllegalArgumentException (fromIndex + " > " + toIndex); 425 if (fromIndex < 0 || toIndex > size()) 426 throw new IndexOutOfBoundsException (); 427 428 if (this instanceof RandomAccess ) { 429 return (List ) database().createObject( 430 _BaseList_RandomAccessSubListImpl.class, 431 new Class [] {BaseList.class, int.class, int.class}, 432 new Object [] {self(), new Integer (fromIndex), new Integer (toIndex)}); 433 } 434 return (List ) database().createObject( 435 _BaseList_SubListImpl.class, 436 new Class [] {BaseList.class, int.class, int.class}, 437 new Object [] {self(), new Integer (fromIndex), new Integer (toIndex)} 438 ); 439 } 440 public List getClientList() { 441 return (List ) getClientCollection(); 442 } 443 444 protected Iterator internalIterator() { 445 return null; 447 } 448 449 } 450 | Popular Tags |