1 18 package org.apache.beehive.netui.script.el.util; 19 20 import java.util.Collection ; 21 import java.util.Enumeration ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import java.util.Set ; 25 26 29 public abstract class AbstractAttributeMap 30 implements Map { 31 32 private Map _map = null; 33 34 protected abstract Object getValue(Object key); 35 36 protected abstract Object putValue(Object key, Object value); 37 38 protected abstract Enumeration getKeysEnumeration(); 39 40 public void clear() { 41 } 42 43 public boolean containsKey(Object key) { 44 return (getValue(key) != null); 45 } 46 47 public boolean containsValue(Object key) { 48 return getMap().containsValue(key); 49 } 50 51 public Set entrySet() { 52 return getMap().entrySet(); 53 } 54 55 public Object get(Object key) { 56 return getValue(key); 57 } 58 59 public boolean isEmpty() { 60 return getMap().isEmpty(); 61 } 62 63 public Set keySet() { 64 return getMap().keySet(); 65 } 66 67 public Object put(Object key, Object value) { 68 return putValue(key, value); 69 } 70 71 public void putAll(Map t) { 72 getMap().putAll(t); 73 } 74 75 public Object remove(Object key) { 76 return getMap().remove(key); 77 } 78 79 public int size() { 80 return getMap().size(); 81 } 82 83 public Collection values() { 84 return getMap().values(); 85 } 86 87 private Map getMap() { 88 if(_map == null) 89 _map = convertToMap(); 90 91 return _map; 92 } 93 94 private Map convertToMap() { 95 if(_map == null) 96 _map = new HashMap (); 97 98 Enumeration keys = getKeysEnumeration(); 99 while(keys.hasMoreElements()) { 100 Object key = keys.nextElement(); 101 _map.put(key, getValue(key)); 102 } 103 104 return _map; 105 } 106 } 107 | Popular Tags |