1 9 package org.ozoneDB.DxLib; 10 11 import java.util.*; 12 13 19 public final class DxHashIterator extends DxAbstractIterator { 20 21 final static long serialVersionUID = 1L; 22 23 Enumeration keyEnum; 24 Enumeration objEnum; 25 Object currentKey; 26 Object currentObject; 27 Hashtable ht; 28 29 30 32 public DxHashIterator( DxHashCollection _coll ) { 33 ht = _coll.internalHashtable(); 34 reset(); 35 } 36 37 38 40 public Object object() { 41 return currentObject; 42 } 43 44 45 47 public Object key() { 48 return currentKey; 49 } 50 51 52 54 public Object next() { 55 if (atFirstObject) { 56 atFirstObject = false; 57 } else { 58 if (objEnum.hasMoreElements()) { 59 currentObject = objEnum.nextElement(); 60 currentKey = keyEnum.nextElement(); 61 } else { 62 return null; 63 } 64 } 65 return object(); 66 } 67 68 69 71 public void reset() { 72 atFirstObject = true; 73 objectRemoved = false; 74 keyEnum = ht.keys(); 75 objEnum = ht.elements(); 76 if (objEnum.hasMoreElements()) { 77 currentObject = objEnum.nextElement(); 78 } 79 if (keyEnum.hasMoreElements()) { 80 currentKey = keyEnum.nextElement(); 81 } 82 } 83 84 85 87 public synchronized Object removeObject() { 88 return ht.remove( currentKey ); 89 } 90 } 91 | Popular Tags |