1 55 56 package org.apache.commons.el; 57 58 import java.util.Collection ; 59 import java.util.Enumeration ; 60 import java.util.HashMap ; 61 import java.util.Map ; 62 import java.util.Set ; 63 64 78 79 public abstract class EnumeratedMap 80 implements Map 81 { 82 86 Map mMap; 87 88 public void clear () 90 { 91 throw new UnsupportedOperationException (); 92 } 93 94 public boolean containsKey (Object pKey) 96 { 97 return getValue (pKey) != null; 98 } 99 100 public boolean containsValue (Object pValue) 102 { 103 return getAsMap ().containsValue (pValue); 104 } 105 106 public Set entrySet () 108 { 109 return getAsMap ().entrySet (); 110 } 111 112 public Object get (Object pKey) 114 { 115 return getValue (pKey); 116 } 117 118 public boolean isEmpty () 120 { 121 return !enumerateKeys ().hasMoreElements (); 122 } 123 124 public Set keySet () 126 { 127 return getAsMap ().keySet (); 128 } 129 130 public Object put (Object pKey, Object pValue) 132 { 133 throw new UnsupportedOperationException (); 134 } 135 136 public void putAll (Map pMap) 138 { 139 throw new UnsupportedOperationException (); 140 } 141 142 public Object remove (Object pKey) 144 { 145 throw new UnsupportedOperationException (); 146 } 147 148 public int size () 150 { 151 return getAsMap ().size (); 152 } 153 154 public Collection values () 156 { 157 return getAsMap ().values (); 158 } 159 160 167 public abstract Enumeration enumerateKeys (); 168 169 174 public abstract boolean isMutable (); 175 176 182 public abstract Object getValue (Object pKey); 183 184 190 public Map getAsMap () 191 { 192 if (mMap != null) { 193 return mMap; 194 } 195 else { 196 Map m = convertToMap (); 197 if (!isMutable ()) { 198 mMap = m; 199 } 200 return m; 201 } 202 } 203 204 209 Map convertToMap () 210 { 211 Map ret = new HashMap (); 212 for (Enumeration e = enumerateKeys (); e.hasMoreElements (); ) { 213 Object key = e.nextElement (); 214 Object value = getValue (key); 215 ret.put (key, value); 216 } 217 return ret; 218 } 219 220 } 222 | Popular Tags |