1 package org.bsf.smartValueObject.container; 2 3 import org.bsf.smartValueObject.container.SmartCollection; 4 import org.bsf.smartValueObject.container.AbstractSmartContainer; 5 import org.bsf.smartValueObject.Versionable; 6 7 import java.util.*; 8 9 15 public class SmartMap extends AbstractSmartContainer implements Map { 16 private Map map; 17 18 public SmartMap(Map m, Versionable v) { 19 super(v); 20 this.map = m; 21 } 22 23 protected boolean addToContainer(Object o) { 24 return map.put(o, o) == o; 25 } 26 27 protected Object addToContainer(Object key, Object o) { 28 return map.put(key, o); 29 } 30 31 protected Object getFromContainer(Object key) { 32 return map.get(key); 33 } 34 35 protected boolean removeFromContainer(Object o) { 36 throw new UnsupportedOperationException (); 37 } 38 39 protected Object removeKeyFromContainer(Object key) { 40 return map.remove(key); 41 } 42 43 protected boolean containerContains(Object o) { 44 return map.containsValue(o); 45 } 46 47 protected boolean containerContainsKey(Object key) { 48 return map.containsKey(key); 49 } 50 51 protected int containerSize() { 52 return map.size(); 53 } 54 55 protected Iterator containerIterator() { 56 return map.values().iterator(); 57 } 58 59 protected void containerClear() { 60 map.clear(); 61 } 62 63 protected Object [] toObjectArray() { 64 throw new UnsupportedOperationException (); 65 } 66 67 public Object getContainer() { 68 return map; 69 } 70 71 public Object remove(Object key) { 72 return removeObjectByKey(key); 73 } 74 75 public void putAll(Map t) { 76 throw new UnsupportedOperationException (); 77 } 78 79 public Set keySet() { 80 Set set = map.keySet(); 82 Set newset = new HashSet(); 83 Iterator it = set.iterator(); 84 while (it.hasNext()) { 85 Object key = it.next(); 86 Object o = map.get(key); 87 if (o instanceof Versionable) { 88 if (((Versionable) o).isDeleted()) { 89 continue; 90 } 91 } 92 newset.add(key); 93 } 94 95 return newset; 96 } 97 98 public Collection values() { 99 return new SmartCollection(map.values(), this); 101 } 102 103 public Set entrySet() { 104 return new SmartSet(map.entrySet(), this); 105 } 106 107 111 public void clear() { 112 Iterator it = map.keySet().iterator(); 113 while (it.hasNext()) { 114 removeObjectByKey(it.next()); 115 } 116 } 117 } 118 | Popular Tags |