01: package com.ibatis.struts.httpmap;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05: import java.util.Enumeration;
06: import java.util.HashSet;
07: import java.util.Iterator;
08: import java.util.List;
09: import java.util.Map;
10: import java.util.Set;
11:
12: /**
13: * <p/>Date: Mar 11, 2004 10:39:51 PM
14: *
15: * @author Clinton Begin
16: */
17: public abstract class BaseHttpMap implements Map {
18:
19: public int size() {
20: return keySet().size();
21: }
22:
23: public boolean isEmpty() {
24: return keySet().size() == 0;
25: }
26:
27: public boolean containsKey(Object key) {
28: return keySet().contains(key);
29: }
30:
31: public boolean containsValue(Object value) {
32: return values().contains(value);
33: }
34:
35: public Object get(Object key) {
36: return getValue(key);
37: }
38:
39: public Object put(Object key, Object value) {
40: Object old = getValue(key);
41: putValue(key, value);
42: return old;
43: }
44:
45: public Object remove(Object key) {
46: Object old = getValue(key);
47: removeValue(key);
48: return old;
49: }
50:
51: public void putAll(Map map) {
52: Iterator i = map.keySet().iterator();
53: while (i.hasNext()) {
54: Object key = i.next();
55: putValue(key, map.get(key));
56: }
57: }
58:
59: public void clear() {
60: Iterator i = keySet().iterator();
61: while (i.hasNext()) {
62: removeValue(i.next());
63: }
64: }
65:
66: public Set keySet() {
67: Set keySet = new HashSet();
68: Enumeration enum = getNames();
69: while (enum.hasMoreElements()) {
70: keySet.add(enum.nextElement());
71: }
72: return keySet;
73: }
74:
75: public Collection values() {
76: List list = new ArrayList();
77: Enumeration enum = getNames();
78: while (enum.hasMoreElements()) {
79: list.add(getValue(enum.nextElement()));
80: }
81: return list;
82: }
83:
84: public Set entrySet() {
85: return new HashSet();
86: }
87:
88: protected abstract Enumeration getNames();
89:
90: protected abstract Object getValue(Object key);
91:
92: protected abstract void putValue(Object key, Object value);
93:
94: protected abstract void removeValue(Object key);
95:
96: }
|