1 28 29 package HTTPClient; 30 31 32 import java.util.Hashtable; 33 import java.util.Enumeration; 34 35 41 42 class CIHashtable extends Hashtable 43 { 44 46 54 public CIHashtable(int initialCapacity, float loadFactor) 55 { 56 super(initialCapacity, loadFactor); 57 } 58 59 60 66 public CIHashtable(int initialCapacity) 67 { 68 super(initialCapacity); 69 } 70 71 72 77 public CIHashtable() 78 { 79 super(); 80 } 81 82 83 85 93 public Object get(String key) 94 { 95 return super.get(new CIString(key)); 96 } 97 98 99 108 public Object put(String key, Object value) 109 { 110 return super.put(new CIString(key), value); 111 } 112 113 114 122 public boolean containsKey(String key) 123 { 124 return super.contains(new CIString(key)); 125 } 126 127 128 136 public Object remove(String key) 137 { 138 return super.remove(new CIString(key)); 139 } 140 141 142 148 public Enumeration keys() 149 { 150 return new CIHashtableEnumeration(super.keys()); 151 } 152 } 153 154 155 160 final class CIHashtableEnumeration implements Enumeration 161 { 162 Enumeration HTEnum; 163 164 public CIHashtableEnumeration(Enumeration enum) 165 { 166 HTEnum = enum; 167 } 168 169 public boolean hasMoreElements() 170 { 171 return HTEnum.hasMoreElements(); 172 } 173 174 public Object nextElement() 175 { 176 Object tmp = HTEnum.nextElement(); 177 if (tmp instanceof CIString) 178 return ((CIString) tmp).getString(); 179 180 return tmp; 181 } 182 } 183 184 185 193 final class CIString 194 { 195 196 private String string; 197 198 199 private int hash; 200 201 202 203 public CIString(String string) 204 { 205 this.string = string; 206 this.hash = calcHashCode(string); 207 } 208 209 210 public final String getString() 211 { 212 return string; 213 } 214 215 216 public int hashCode() 217 { 218 return hash; 219 } 220 221 222 227 private static final int calcHashCode(String str) 228 { 229 int hash = 0; 230 char llc[] = lc; 231 int len = str.length(); 232 233 for (int idx= 0; idx<len; idx++) 234 hash = 31*hash + llc[str.charAt(idx)]; 235 236 return hash; 237 } 238 239 240 243 public boolean equals(Object obj) 244 { 245 if (obj != null) 246 { 247 if (obj instanceof CIString) 248 return string.equalsIgnoreCase(((CIString) obj).string); 249 250 if (obj instanceof String) 251 return string.equalsIgnoreCase((String) obj); 252 } 253 254 return false; 255 } 256 257 260 public String toString() 261 { 262 return string; 263 } 264 265 266 private static final char[] lc = new char[256]; 267 268 static 269 { 270 for (char idx=0; idx<256; idx++) 272 lc[idx] = Character.toLowerCase(idx); 273 } 274 } 275 276 | Popular Tags |