1 48 49 package org.ozoneDB.collections; 50 51 import java.io.Serializable ; 52 import java.util.ConcurrentModificationException ; 53 import java.util.Iterator ; 54 import java.util.NoSuchElementException ; 55 import org.ozoneDB.OzoneObject; 56 57 65 public class _BaseTreeMap_OzoneTreeIteratorImpl extends OzoneObject implements OzoneIterator { 66 67 private static final long serialVersionUID = 1L; 68 69 private BaseTreeMap owner; 70 71 public _BaseTreeMap_OzoneTreeIteratorImpl(BaseTreeMap owner, int type) { 72 this.owner = owner; 73 knownMod = owner._org_ozoneDB_getModification(); 74 this.type = type; 75 this.next = owner._org_ozoneDB_firstNode(); 76 this.max = BaseTreeMapImpl.nilNode; 77 valid = true; 78 } 79 80 public _BaseTreeMap_OzoneTreeIteratorImpl(BaseTreeMap owner, int type, BaseTreeMap.Node first, BaseTreeMap.Node max) { 81 this.owner = owner; 82 knownMod = owner._org_ozoneDB_getModification(); 83 this.type = type; 84 this.next = first; 85 this.max = max; 86 valid = true; 87 } 88 89 93 private final int type; 94 95 private int knownMod; 96 97 private BaseTreeMap.Node last; 98 99 private BaseTreeMap.Node next; 100 104 private final BaseTreeMap.Node max; 105 106 112 private transient boolean valid = false; 113 114 119 private _BaseTreeMap_OzoneTreeIteratorImpl(int type) { 120 this.type = type; 123 this.next = owner._org_ozoneDB_firstNode(); 124 this.max = BaseTreeMapImpl.nilNode; 125 valid = true; 126 } 127 128 137 private _BaseTreeMap_OzoneTreeIteratorImpl(int type, BaseTreeMap.Node first, BaseTreeMap.Node max) { 138 this.type = type; 139 this.next = first; 140 this.max = max; 141 valid = true; 142 } 143 144 149 public boolean hasNext() { 150 if (!valid) { 151 throw new ConcurrentModificationException ("iterator has been persisted and reloaded; see javadoc on FullTreeMapImpl"); 152 } 153 if (knownMod != owner._org_ozoneDB_getModification()) 154 throw new ConcurrentModificationException (); 155 return !next.equals(max); 156 } 157 158 164 public Object next() { 165 if (!valid) { 166 throw new ConcurrentModificationException ("iterator has been persisted and reloaded; see javadoc on FullTreeMapImpl"); 167 } 168 if (knownMod != owner._org_ozoneDB_getModification()) 169 throw new ConcurrentModificationException (); 170 if (next.equals(max)) 171 throw new NoSuchElementException (); 172 last = next; 173 next = owner._org_ozoneDB_successor(last); 174 175 if (type == BaseTreeMapImpl.VALUES) 176 return last.getValue(); 177 else if (type == BaseTreeMapImpl.KEYS) 178 return last.getKey(); 179 return last; 180 } 181 182 188 public void remove() { 189 if (last == null) { 190 throw new IllegalStateException (); 191 } 192 if (!valid) { 193 throw new ConcurrentModificationException ("iterator has been persisted and reloaded; see javadoc on FullTreeMapImpl"); 194 } 195 if (knownMod != owner._org_ozoneDB_getModification()) { 196 throw new ConcurrentModificationException (); 197 } 198 199 owner._org_ozoneDB_removeNode(last); 200 last = null; 201 knownMod++; 202 } 203 204 } | Popular Tags |