1 47 48 package org.ozoneDB.collections; 49 50 import java.util.ConcurrentModificationException ; 51 import java.util.NoSuchElementException ; 52 import org.ozoneDB.OzoneObject; 53 54 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 68 public _BaseList_IteratorImpl(BaseList owner) { 69 this.owner = owner; 70 knownMod = owner._org_ozoneDB_getModCount(); 71 } 72 73 private void checkMod() { 75 if (knownMod != owner._org_ozoneDB_getModCount()) { 76 throw new ConcurrentModificationException (); 77 } 78 } 79 80 public boolean hasNext() { 81 checkMod(); 82 return pos < size; 83 } 84 85 public Object next() { 86 checkMod(); 87 if (pos == size) { 88 throw new NoSuchElementException (); 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 (); 98 } 99 owner.remove(last); 100 pos--; 101 size--; 102 last = -1; 103 knownMod = owner._org_ozoneDB_getModCount(); 104 } 105 106 } | Popular Tags |