View Javadoc

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