KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > script > el > util > AbstractAttributeMap


1 /*
2  * Copyright 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  * $Header:$
17  */

18 package org.apache.beehive.netui.script.el.util;
19
20 import java.util.Collection JavaDoc;
21 import java.util.Enumeration JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.Set JavaDoc;
25
26 /**
27  *
28  */

29 public abstract class AbstractAttributeMap
30     implements Map JavaDoc {
31
32     private Map JavaDoc _map = null;
33
34     protected abstract Object JavaDoc getValue(Object JavaDoc key);
35
36     protected abstract Object JavaDoc putValue(Object JavaDoc key, Object JavaDoc value);
37
38     protected abstract Enumeration JavaDoc getKeysEnumeration();
39
40     public void clear() {
41     }
42
43     public boolean containsKey(Object JavaDoc key) {
44         return (getValue(key) != null);
45     }
46
47     public boolean containsValue(Object JavaDoc key) {
48         return getMap().containsValue(key);
49     }
50
51     public Set JavaDoc entrySet() {
52         return getMap().entrySet();
53     }
54
55     public Object JavaDoc get(Object JavaDoc key) {
56         return getValue(key);
57     }
58
59     public boolean isEmpty() {
60         return getMap().isEmpty();
61     }
62
63     public Set JavaDoc keySet() {
64         return getMap().keySet();
65     }
66
67     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
68         return putValue(key, value);
69     }
70
71     public void putAll(Map JavaDoc t) {
72         getMap().putAll(t);
73     }
74
75     public Object JavaDoc remove(Object JavaDoc key) {
76         return getMap().remove(key);
77     }
78
79     public int size() {
80         return getMap().size();
81     }
82
83     public Collection JavaDoc values() {
84         return getMap().values();
85     }
86
87     private Map JavaDoc getMap() {
88         if(_map == null)
89             _map = convertToMap();
90
91         return _map;
92     }
93
94     private Map JavaDoc convertToMap() {
95         if(_map == null)
96             _map = new HashMap JavaDoc();
97
98         Enumeration JavaDoc keys = getKeysEnumeration();
99         while(keys.hasMoreElements()) {
100             Object JavaDoc key = keys.nextElement();
101             _map.put(key, getValue(key));
102         }
103
104         return _map;
105     }
106 }
107
Popular Tags