KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > genclass > map > HashMapImpl


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.genclass.map;
19
20 import org.objectweb.speedo.genclass.api.SpeedoGenClassProxy;
21 import org.objectweb.speedo.mim.api.SpeedoAccessor;
22
23 import java.util.Map JavaDoc;
24 import java.util.Set JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.util.HashMap JavaDoc;
27
28 /**
29  *
30  * @author S.Chassande-Barrioz
31  */

32 public abstract class HashMapImpl
33         extends HashMap JavaDoc
34         implements SpeedoGenClassProxy {
35
36     public HashMapImpl() {
37         super();
38         accessor = (MapAccessor) createAccessor();
39     }
40
41     public String JavaDoc toString() {
42         return "";
43     }
44
45     MapAccessor accessor;
46
47     public SpeedoAccessor getReferenceAccessor() {
48         return accessor;
49     }
50     public void setReferenceAccessor(SpeedoAccessor refAcc) {
51         accessor = (MapAccessor) refAcc;
52     }
53
54     public Object JavaDoc createGenClass() {
55         return new HashMap JavaDoc();
56     }
57
58     public SpeedoAccessor createAccessor() {
59         return new MapAccessor(this);
60     }
61
62     // IMPLEMENTS THE HashSet CLASS //
63
//------------------------------//
64

65     public int size() {
66         if (!jdoIsActive()) {
67             return accessor.size();
68         } else {
69             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
70             return ma.size();
71         }
72     }
73
74     public boolean isEmpty() {
75         if (!jdoIsActive()) {
76             return accessor.isEmpty();
77         } else {
78             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
79             return ma.isEmpty();
80         }
81     }
82
83     public boolean containsValue(Object JavaDoc o) {
84         if (!jdoIsActive()) {
85             return accessor.containsValue(o);
86         } else {
87             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
88             return ma.containsValue(o);
89         }
90     }
91
92     public synchronized boolean containsKey(Object JavaDoc o) {
93         if (!jdoIsActive()) {
94             return accessor.containsKey(o);
95         } else {
96             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
97             return ma.containsKey(o);
98         }
99     }
100
101     public synchronized Object JavaDoc get(Object JavaDoc o) {
102         if (!jdoIsActive()) {
103             return accessor.get(o);
104         } else {
105             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
106             return ma.get(o);
107         }
108     }
109
110     public synchronized Object JavaDoc put(Object JavaDoc o, Object JavaDoc o1) {
111         if (!jdoIsActive()) {
112             return accessor.put(o, o1);
113         } else {
114             MapAccessor ma = (MapAccessor) getSpeedoHome().writeIntention(this, null);
115             return ma.put(o, o1);
116         }
117     }
118
119     public synchronized Object JavaDoc remove(Object JavaDoc o) {
120         if (!jdoIsActive()) {
121             return accessor.remove(o);
122         } else {
123             MapAccessor ma = (MapAccessor) getSpeedoHome().writeIntention(this, null);
124             return ma.remove(o);
125         }
126     }
127
128     public synchronized void putAll(Map JavaDoc map) {
129         if (!jdoIsActive()) {
130             accessor.putAll(map);
131         } else {
132             MapAccessor ma = (MapAccessor) getSpeedoHome().writeIntention(this, null);
133             ma.putAll(map);
134         }
135     }
136
137     public synchronized void clear() {
138         if (!jdoIsActive()) {
139             accessor.clear();
140         } else {
141             MapAccessor ma = (MapAccessor) getSpeedoHome().writeIntention(this, null);
142             ma.clear();
143         }
144     }
145
146     public Set JavaDoc keySet() {
147         if (!jdoIsActive()) {
148             return accessor.keySet();
149         } else {
150             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
151             return ma.keySet();
152         }
153     }
154
155     public Set JavaDoc entrySet() {
156         if (!jdoIsActive()) {
157             return accessor.entrySet();
158         } else {
159             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
160             return ma.entrySet();
161         }
162     }
163
164     public Collection JavaDoc values() {
165         if (!jdoIsActive()) {
166             return accessor.values();
167         } else {
168             MapAccessor ma = (MapAccessor) getSpeedoHome().readIntention(this, null);
169             return ma.values();
170         }
171     }
172 }
173
174
Popular Tags