1 30 31 32 package org.hsqldb.lib; 33 34 import org.hsqldb.store.BaseHashMap; 35 36 43 public class HashMap extends BaseHashMap { 44 45 Set keySet; 46 Collection values; 47 48 public HashMap() { 49 this(16, 0.75f); 50 } 51 52 public HashMap(int initialCapacity) throws IllegalArgumentException { 53 this(initialCapacity, 0.75f); 54 } 55 56 public HashMap(int initialCapacity, 57 float loadFactor) throws IllegalArgumentException { 58 super(initialCapacity, loadFactor, BaseHashMap.objectKeyOrValue, 59 BaseHashMap.objectKeyOrValue, false); 60 } 61 62 public Object get(Object key) { 63 64 int hash = key.hashCode(); 65 int lookup = getLookup(key, hash); 66 67 if (lookup != -1) { 68 return objectValueTable[lookup]; 69 } 70 71 return null; 72 } 73 74 public Object put(Object key, Object value) { 75 return super.addOrRemove(0, 0, key, value, false); 76 } 77 78 public Object remove(Object key) { 79 return super.removeObject(key); 80 } 81 82 public boolean containsKey(Object key) { 83 return super.containsKey(key); 84 } 85 86 public boolean containsValue(Object value) { 87 return super.containsValue(value); 88 } 89 90 public void putAll(HashMap t) { 91 92 Iterator it = t.keySet.iterator(); 93 94 while (it.hasNext()) { 95 Object key = it.next(); 96 97 put(key, t.get(key)); 98 } 99 } 100 101 public Set keySet() { 102 103 if (keySet == null) { 104 keySet = new KeySet(); 105 } 106 107 return keySet; 108 } 109 110 public Collection values() { 111 112 if (values == null) { 113 values = new Values(); 114 } 115 116 return values; 117 } 118 119 class KeySet implements Set { 120 121 public Iterator iterator() { 122 return HashMap.this.new BaseHashIterator(true); 123 } 124 125 public int size() { 126 return HashMap.this.size(); 127 } 128 129 public boolean contains(Object o) { 130 return containsKey(o); 131 } 132 133 public Object get(Object key) { 134 135 int lookup = HashMap.this.getLookup(key, key.hashCode()); 136 137 if (lookup < 0) { 138 return null; 139 } else { 140 return HashMap.this.objectKeyTable[lookup]; 141 } 142 } 143 144 public boolean add(Object value) { 145 throw new RuntimeException (); 146 } 147 148 public boolean addAll(Collection c) { 149 throw new RuntimeException (); 150 } 151 152 public boolean remove(Object o) { 153 154 int oldSize = size(); 155 156 HashMap.this.remove(o); 157 158 return size() != oldSize; 159 } 160 161 public boolean isEmpty() { 162 return size() == 0; 163 } 164 165 public void clear() { 166 HashMap.this.clear(); 167 } 168 } 169 170 class Values implements Collection { 171 172 public Iterator iterator() { 173 return HashMap.this.new BaseHashIterator(false); 174 } 175 176 public int size() { 177 return HashMap.this.size(); 178 } 179 180 public boolean contains(Object o) { 181 throw new RuntimeException (); 182 } 183 184 public boolean add(Object value) { 185 throw new RuntimeException (); 186 } 187 188 public boolean addAll(Collection c) { 189 throw new RuntimeException (); 190 } 191 192 public boolean remove(Object o) { 193 throw new RuntimeException (); 194 } 195 196 public boolean isEmpty() { 197 return size() == 0; 198 } 199 200 public void clear() { 201 HashMap.this.clear(); 202 } 203 } 204 } 205 | Popular Tags |