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 56 62 public final class _BaseTreeMap_TreeIterator implements Iterator , Serializable { 63 64 private static final long serialVersionUID = 1L; 65 66 private BaseTreeMap owner; 67 68 public _BaseTreeMap_TreeIterator(BaseTreeMap owner, int type) { 69 this.owner = owner; 70 knownMod = owner._org_ozoneDB_getModification(); 71 this.type = type; 72 this.next = owner._org_ozoneDB_firstNode(); 73 this.max = BaseTreeMapImpl.nilNode; 74 } 75 76 public _BaseTreeMap_TreeIterator(BaseTreeMap owner, int type, BaseTreeMap.Node first, BaseTreeMap.Node max) { 77 this.owner = owner; 78 knownMod = owner._org_ozoneDB_getModification(); 79 this.type = type; 80 this.next = first; 81 this.max = max; 82 } 83 84 88 private final int type; 89 90 private int knownMod; 91 92 private BaseTreeMap.Node last; 93 94 private BaseTreeMap.Node next; 95 99 private final BaseTreeMap.Node max; 100 101 106 private _BaseTreeMap_TreeIterator(int type) { 107 this.type = type; 110 this.next = owner._org_ozoneDB_firstNode(); 111 this.max = BaseTreeMapImpl.nilNode; 112 } 113 114 123 private _BaseTreeMap_TreeIterator(int type, BaseTreeMap.Node first, BaseTreeMap.Node max) { 124 this.type = type; 125 this.next = first; 126 this.max = max; 127 } 128 129 134 public boolean hasNext() { 135 if (knownMod != owner._org_ozoneDB_getModification()) 136 throw new ConcurrentModificationException (); 137 return !next.equals(max); 138 } 139 140 146 public Object next() { 147 if (knownMod != owner._org_ozoneDB_getModification()) 148 throw new ConcurrentModificationException (); 149 if (next.equals(max)) 150 throw new NoSuchElementException (); 151 last = next; 152 next = owner._org_ozoneDB_successor(last); 153 154 if (type == BaseTreeMapImpl.VALUES) 155 return last.getValue(); 156 else if (type == BaseTreeMapImpl.KEYS) 157 return last.getKey(); 158 return last; 159 } 160 161 167 public void remove() { 168 if (last == null) { 169 throw new IllegalStateException (); 170 } 171 if (knownMod != owner._org_ozoneDB_getModification()) { 172 throw new ConcurrentModificationException (); 173 } 174 175 owner._org_ozoneDB_removeNode(last); 176 last = null; 177 knownMod++; 178 } 179 180 } | Popular Tags |