1 9 package org.ozoneDB.DxLib; 10 11 import java.util.Hashtable ; 12 13 14 24 public class DxHashMap extends DxAbstractMap implements DxHashCollection { 25 26 final static long serialVersionUID = 1L; 27 28 protected transient Hashtable ht; 29 30 31 public DxHashMap() { 32 ht = new Hashtable (); 33 } 34 35 36 public DxHashMap( int size ) { 37 ht = new Hashtable ( size ); 38 } 39 40 41 public Object clone() { 42 DxMap newMap = new DxHashMap( Math.max( count(), 8 ) ); 43 return clone( newMap ); 44 } 45 46 47 public boolean addForKey( Object obj, Object key ) { 48 synchronized (ht) { 49 Object old = ht.put( key, obj ); 50 if (old != null) { 51 ht.put( key, old ); 52 return false; 53 } 54 return true; 55 } 56 } 57 58 59 public Object elementForKey( Object key ) { 60 return ht.get( key ); 61 } 62 63 64 public Object keyForElement( Object obj ) { 65 DxIterator it = iterator(); 66 Object cursor; 67 while ((cursor = it.next()) != null) { 68 if (obj.equals( cursor )) { 69 return it.key(); 70 } 71 } 72 return null; 73 } 74 75 76 public Object removeForKey( Object key ) { 77 return ht.remove( key ); 78 } 79 80 81 public synchronized boolean remove( Object obj ) { 82 Object key = keyForElement( obj ); 83 if (key != null) { 84 removeForKey( key ); 85 return true; 86 } 87 return false; 88 } 89 90 91 public int count() { 92 return ht.size(); 93 } 94 95 96 public boolean isEmpty() { 97 return ht.isEmpty(); 98 } 99 100 101 public boolean containsKey( Object key ) { 102 return ht.containsKey( key ); 103 } 104 105 106 public DxIterator iterator() { 107 return new DxHashIterator( this ); 108 } 109 110 111 public void clear() { 112 ht.clear(); 113 } 114 115 116 public Hashtable internalHashtable() { 117 return ht; 118 } 119 } 120 | Popular Tags |