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 56 65 public class _BaseList_SubListImpl extends BaseListImpl implements _BaseList_SubList { 66 67 68 private final BaseList backingList; 69 70 71 private final int offset; 72 73 74 private int size; 75 76 83 public _BaseList_SubListImpl(BaseList backingList, int fromIndex, int toIndex) { 84 this.backingList = backingList; 85 modCount = backingList._org_ozoneDB_getModCount(); 86 offset = fromIndex; 87 size = toIndex - fromIndex; 88 } 89 90 97 public void _org_ozoneDB_checkMod() { 98 if (modCount != backingList._org_ozoneDB_getModCount()) { 99 throw new ConcurrentModificationException (); 100 } 101 } 102 103 110 public void _org_ozoneDB_checkBoundsInclusive(int index) { 111 if (index < 0 || index > size) 112 throw new IndexOutOfBoundsException ("Index: " + index + ", Size:" 113 + size); 114 } 115 116 123 public void _org_ozoneDB_checkBoundsExclusive(int index) { 125 if (index < 0 || index >= size) 126 throw new IndexOutOfBoundsException ("Index: " + index + ", Size:" 127 + size); 128 } 129 130 135 public int size() { 136 _org_ozoneDB_checkMod(); 137 return size; 138 } 139 140 147 public Object set(int index, Object o) { 148 _org_ozoneDB_checkMod(); 149 _org_ozoneDB_checkBoundsExclusive(index); 150 return backingList.set(index + offset, o); 151 } 152 153 159 public Object get(int index) { 160 _org_ozoneDB_checkMod(); 161 _org_ozoneDB_checkBoundsExclusive(index); 162 return backingList.get(index + offset); 163 } 164 165 171 public void add(int index, Object o) { 172 _org_ozoneDB_checkMod(); 173 _org_ozoneDB_checkBoundsInclusive(index); 174 backingList.add(index + offset, o); 175 size++; 176 modCount = backingList._org_ozoneDB_getModCount(); 177 } 178 179 185 public Object remove(int index) { 186 _org_ozoneDB_checkMod(); 187 _org_ozoneDB_checkBoundsExclusive(index); 188 Object o = backingList.remove(index + offset); 189 size--; 190 modCount = backingList._org_ozoneDB_getModCount(); 191 return o; 192 } 193 194 202 public void _org_ozoneDB_removeRange(int fromIndex, int toIndex) { 203 _org_ozoneDB_checkMod(); 204 205 backingList._org_ozoneDB_removeRange(offset + fromIndex, offset + toIndex); 206 size -= toIndex - fromIndex; 207 modCount = backingList._org_ozoneDB_getModCount(); 208 } 209 210 217 public boolean addAll(int index, Collection c) { 218 _org_ozoneDB_checkMod(); 219 _org_ozoneDB_checkBoundsInclusive(index); 220 int csize = c.size(); 221 boolean result = backingList.addAll(offset + index, c); 222 size += csize; 223 modCount = backingList._org_ozoneDB_getModCount(); 224 return result; 225 } 226 227 233 public boolean addAll(Collection c) { 234 return addAll(size, c); 235 } 236 237 public Iterator _org_ozoneDB_internalIterator() { 238 throw new RuntimeException ("_org_ozoneDB_internalIterator(), Not yet Implemented"); 239 } 240 241 246 public Iterator iterator() { 247 return listIterator(); 248 } 249 250 254 261 public ListIterator listIterator(final int index) { 262 _org_ozoneDB_checkMod(); 263 _org_ozoneDB_checkBoundsInclusive(index); 264 265 266 OzoneListIterator iterator = (OzoneListIterator) backingList.listIterator(index + offset); 267 ListIterator result = (ListIterator ) database().createObject( 269 _BaseList_SubList_listIterator.class, 270 new Class [] {_BaseList_SubList.class, OzoneListIterator.class}, 271 new Object [] {self(), iterator} 272 ); 273 return result; 274 } 275 276 public int _org_ozoneDB_getModCount() { 277 return modCount; 278 } 279 280 public void _org_ozoneDB_incSize(int amount) { 281 size += amount; 282 } 283 284 public List getClientList() { 285 List result = backingList._org_ozoneDB_emptyClientCollection(); 286 result.addAll((List ) self()); 287 return result; 288 } 289 290 public int _org_ozoneDB_getOffset() { 291 return offset; 292 } 293 294 public List _org_ozoneDB_emptyClientCollection() { 295 return backingList._org_ozoneDB_emptyClientCollection(); 296 } 297 298 public void _org_ozoneDB_syncModCountWithBackingList() { 299 modCount = backingList._org_ozoneDB_getModCount(); 300 } 301 302 } 303 | Popular Tags |