1 20 package org.enhydra.barracuda.plankton.data; 21 22 import java.io.*; 23 import java.util.*; 24 25 30 public class PHashMap extends AbstractPData implements PMap { 31 32 private Map map = new HashMap(); 33 34 35 44 public void setStore(Map imap) { 45 map = imap; 46 } 47 48 49 53 public void clear() { 54 Iterator it = map.values().iterator(); 56 while (it.hasNext()) { 57 Object el = it.next(); 58 if (el!=null && el instanceof PData) { 59 PData pdata = (PData) el; 60 if (pdata.isInheritParents() && pdata.getParent()==this) pdata.setParent(null); } 63 } 64 65 map.clear(); 67 } 68 69 72 public boolean containsKey(Object key) { 73 return map.containsKey(key); 74 } 75 76 79 public boolean containsValue(Object value) { 80 return map.containsValue(value); 81 } 82 83 86 public Set entrySet() { 87 return map.entrySet(); 88 } 89 90 93 public Object get(Object key) { 94 return map.get(key); 95 } 96 97 100 public boolean isEmpty() { 101 return map.isEmpty(); 102 } 103 104 107 public Set keySet() { 108 return map.keySet(); 109 } 110 111 114 public Object put(Object key, Object value) { 115 116 Object curEl = map.get(key); 122 if (curEl!=null && curEl instanceof PData) { 123 PData pdata = (PData) curEl; 124 if (pdata.isInheritParents() && pdata.getParent()==this) pdata.setParent(null); } 127 128 if (value!=null && value instanceof PData) { 133 PData pdata = (PData) value; 134 if (pdata.isInheritParents() && pdata.getParent()==null) pdata.setParent(this); } 137 138 return map.put(key, value); 140 } 141 142 145 public void putAll(Map imap) { 146 147 Iterator it = imap.keySet().iterator(); 153 while (it.hasNext()) { 154 Object key = it.next(); 155 156 Object ovalue = map.get(key); 158 if (ovalue!=null && ovalue instanceof PData) { 159 PData pdata = (PData) ovalue; 160 if (pdata.isInheritParents() && pdata.getParent()==this) pdata.setParent(null); } 163 164 Object nvalue = imap.get(key); 166 if (nvalue!=null && nvalue instanceof PData) { 167 PData pdata = (PData) nvalue; 168 if (pdata.isInheritParents() && pdata.getParent()==null) pdata.setParent(this); } 171 } 172 173 map.putAll(imap); 175 } 176 177 180 public Object remove(Object key) { 181 Object value = map.get(key); 183 if (value!=null && value instanceof PData) { 184 PData pdata = (PData) value; 185 if (pdata.isInheritParents() && pdata.getParent()==this) pdata.setParent(null); } 188 189 return map.remove(key); 191 } 192 193 196 public int size() { 197 return map.size(); 198 } 199 200 203 public Collection values() { 204 return map.values(); 205 } 206 207 208 215 public Object clone() { 216 try { 217 PHashMap phm = (PHashMap) super.clone(); 218 phm.map = new HashMap(map); 219 return phm; 220 } catch (CloneNotSupportedException e) { 221 throw new InternalError (); 223 } 224 } 225 226 227 237 public boolean equals(Object obj) { 238 if (obj==null) return false; 239 if (obj==this) return true; 240 if (!(obj instanceof PMap)) return false; 241 PMap pm = (PMap) obj; 242 if (this.size()!=pm.size()) return false; 243 Iterator it = this.keySet().iterator(); 244 while (it.hasNext()) { 245 if (!pm.containsKey(it.next())) return false; 246 } 247 it = this.values().iterator(); 248 while (it.hasNext()) { 249 if (!pm.containsValue(it.next())) return false; 250 } 251 return true; 252 } 253 254 257 public int hashCode() { 258 return map.hashCode(); 259 } 260 261 262 264 265 266 } 267 268 269 | Popular Tags |