View Javadoc

1   /*
2    * Copyright 2000-2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.ibatis.struts.httpmap;
17  
18  import java.util.*;
19  
20  /***
21   * <p/>
22   * Date: Mar 11, 2004 10:39:51 PM
23   *
24   * @author Clinton Begin
25   */
26  public abstract class BaseHttpMap implements Map {
27  
28    public int size() {
29      return keySet().size();
30    }
31  
32    public boolean isEmpty() {
33      return keySet().size() == 0;
34    }
35  
36    public boolean containsKey(Object key) {
37      return keySet().contains(key);
38    }
39  
40    public boolean containsValue(Object value) {
41      return values().contains(value);
42    }
43  
44    public Object get(Object key) {
45      return getValue(key);
46    }
47  
48    public Object put(Object key, Object value) {
49      Object old = getValue(key);
50      putValue(key, value);
51      return old;
52    }
53  
54    public Object remove(Object key) {
55      Object old = getValue(key);
56      removeValue(key);
57      return old;
58    }
59  
60    public void putAll(Map map) {
61      Iterator i = map.keySet().iterator();
62      while (i.hasNext()) {
63        Object key = i.next();
64        putValue(key, map.get(key));
65      }
66    }
67  
68    public void clear() {
69      Iterator i = keySet().iterator();
70      while (i.hasNext()) {
71        removeValue(i.next());
72      }
73    }
74  
75    public Set keySet() {
76      Set keySet = new HashSet();
77      Enumeration names = getNames();
78      while (names.hasMoreElements()) {
79        keySet.add(names.nextElement());
80      }
81      return keySet;
82    }
83  
84    public Collection values() {
85      List list = new ArrayList();
86      Enumeration names = getNames();
87      while (names.hasMoreElements()) {
88        list.add(getValue(names.nextElement()));
89      }
90      return list;
91    }
92  
93    public Set entrySet() {
94      return new HashSet();
95    }
96  
97  
98    protected abstract Enumeration getNames();
99  
100   protected abstract Object getValue(Object key);
101 
102   protected abstract void putValue(Object key, Object value);
103 
104   protected abstract void removeValue(Object key);
105 
106 }