1 48 49 package org.ozoneDB.collections; 50 51 52 import java.io.ObjectOutputStream ; 53 import java.io.ObjectInputStream ; 54 import java.io.IOException ; 55 import java.util.Comparator ; 56 import java.util.Map ; 57 import java.util.SortedMap ; 58 116 public class FullTreeMapImpl extends BaseTreeMapImpl implements FullTreeMap { 117 124 private static final long serialVersionUID = 1L; 125 126 private class Node extends AbstractOzoneMap.AbstractNode implements BaseTreeMap.Node { 127 128 private static final long serialVersionUID = 1L; 129 130 private int color; 131 132 private BaseTreeMap.Node left = BaseTreeMapImpl.nilNode; 133 134 private BaseTreeMap.Node right = BaseTreeMapImpl.nilNode; 135 136 private BaseTreeMap.Node parent = BaseTreeMapImpl.nilNode; 137 138 public Node(Object key, Object value, int color) { 139 super(key, value); 140 setColor(color); 141 } 142 143 public void setRight(BaseTreeMap.Node right) { 144 this.right = right; 145 } 146 147 public void setParent(BaseTreeMap.Node parent) { 148 this.parent = parent; 149 } 150 151 public void setLeft(BaseTreeMap.Node left) { 152 this.left = left; 153 } 154 155 public void setColor(int color) { 156 this.color = color; 157 } 158 159 public BaseTreeMap.Node getRight() { 160 return right; 161 } 162 163 public BaseTreeMap.Node getParent() { 164 return parent; 165 } 166 167 public BaseTreeMap.Node getLeft() { 168 return left; 169 } 170 171 public int getColor() { 172 return color; 173 } 174 175 public boolean isNil() { 176 return false; 177 } 178 179 } 180 181 190 public FullTreeMapImpl() { 191 } 192 193 202 public FullTreeMapImpl(Comparator c) { 203 super(c); 204 } 205 206 220 public FullTreeMapImpl(Map map) { 221 super(map); 222 } 223 224 232 public FullTreeMapImpl(SortedMap sm) { 233 super(sm); } 235 236 protected BaseTreeMap emptyClone() { 237 return (BaseTreeMap) database().createObject(FullTreeMapImpl.class); 240 } 241 242 protected BaseTreeMap.Node newNode(Object key, Object value, int color) { 243 BaseTreeMap.Node result = new Node(key, value, color); 244 return result; 245 } 246 247 256 private void readObject(ObjectInputStream s) throws IOException , ClassNotFoundException { 257 root = nilNode; 258 s.defaultReadObject(); 259 putFromObjStream(s, size, true); 260 } 261 262 271 private void putFromObjStream(ObjectInputStream s, int count, boolean readValues) 272 throws IOException , ClassNotFoundException { 273 _org_ozoneDB_fabricateTree(count); 274 BaseTreeMap.Node node = _org_ozoneDB_firstNode(); 275 276 while (--count >= 0) { 277 node.setKey(s.readObject()); 278 node.setValue(readValues ? s.readObject() : ""); 279 node = _org_ozoneDB_successor(node); 280 } 281 } 282 283 291 private void writeObject(ObjectOutputStream s) throws IOException { 292 s.defaultWriteObject(); 293 294 BaseTreeMap.Node node = _org_ozoneDB_firstNode(); 295 while (!node.isNil()) { 296 s.writeObject(node.getKey()); 297 s.writeObject(node.getValue()); 298 node = _org_ozoneDB_successor(node); 299 } 300 } 301 302 public boolean _org_ozoneDB_alwaysUseInternalIterator() { 303 return false; 304 } 305 306 311 public void onActivate() { 312 modCount += Integer.MAX_VALUE / 2; 328 } 329 330 } | Popular Tags |