001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.genclass.map;
018:
019: import org.objectweb.speedo.genclass.api.SpeedoGenClassPO;
020: import org.objectweb.speedo.mim.api.StateItf;
021:
022: import java.util.Map;
023: import java.util.Set;
024: import java.util.Collection;
025: import java.util.HashMap;
026:
027: /**
028: *
029: * @author S.Chassande-Barrioz
030: */
031: public abstract class HashMapImpl extends HashMap implements
032: SpeedoGenClassPO {
033:
034: public HashMapImpl() {
035: super ();
036: accessor = (MapAccessor) speedoCreateState();
037: }
038:
039: public String toString() {
040: return "";
041: }
042:
043: MapAccessor accessor;
044:
045: public StateItf speedoGetReferenceState() {
046: return accessor;
047: }
048:
049: public void speedoSetReferenceState(StateItf refAcc) {
050: accessor = (MapAccessor) refAcc;
051: }
052:
053: public Object createGenClass() {
054: return new HashMap();
055: }
056:
057: public StateItf speedoCreateState() {
058: return new MapAccessor(this );
059: }
060:
061: // IMPLEMENTS THE HashSet CLASS //
062: //------------------------------//
063:
064: public int size() {
065: if (!speedoIsActive()) {
066: return accessor.size();
067: } else {
068: MapAccessor ma = (MapAccessor) speedoGetHome()
069: .readIntention(this , null);
070: return ma.size();
071: }
072: }
073:
074: public boolean isEmpty() {
075: if (!speedoIsActive()) {
076: return accessor.isEmpty();
077: } else {
078: MapAccessor ma = (MapAccessor) speedoGetHome()
079: .readIntention(this , null);
080: return ma.isEmpty();
081: }
082: }
083:
084: public boolean containsValue(Object o) {
085: if (!speedoIsActive()) {
086: return accessor.containsValue(o);
087: } else {
088: MapAccessor ma = (MapAccessor) speedoGetHome()
089: .readIntention(this , null);
090: return ma.containsValue(o);
091: }
092: }
093:
094: public synchronized boolean containsKey(Object o) {
095: if (!speedoIsActive()) {
096: return accessor.containsKey(o);
097: } else {
098: MapAccessor ma = (MapAccessor) speedoGetHome()
099: .readIntention(this , null);
100: return ma.containsKey(o);
101: }
102: }
103:
104: public synchronized Object get(Object o) {
105: if (!speedoIsActive()) {
106: return accessor.get(o);
107: } else {
108: MapAccessor ma = (MapAccessor) speedoGetHome()
109: .readIntention(this , null);
110: return ma.get(o);
111: }
112: }
113:
114: public synchronized Object put(Object o, Object o1) {
115: if (!speedoIsActive()) {
116: return accessor.put(o, o1);
117: } else {
118: MapAccessor ma = (MapAccessor) speedoGetHome()
119: .writeIntention(this , null);
120: return ma.put(o, o1);
121: }
122: }
123:
124: public synchronized Object remove(Object o) {
125: if (!speedoIsActive()) {
126: return accessor.remove(o);
127: } else {
128: MapAccessor ma = (MapAccessor) speedoGetHome()
129: .writeIntention(this , null);
130: return ma.remove(o);
131: }
132: }
133:
134: public synchronized void putAll(Map map) {
135: if (!speedoIsActive()) {
136: accessor.putAll(map);
137: } else {
138: MapAccessor ma = (MapAccessor) speedoGetHome()
139: .writeIntention(this , null);
140: ma.putAll(map);
141: }
142: }
143:
144: public synchronized void clear() {
145: if (!speedoIsActive()) {
146: accessor.clear();
147: } else {
148: MapAccessor ma = (MapAccessor) speedoGetHome()
149: .writeIntention(this , null);
150: ma.clear();
151: }
152: }
153:
154: public Set keySet() {
155: if (!speedoIsActive()) {
156: return accessor.keySet();
157: } else {
158: MapAccessor ma = (MapAccessor) speedoGetHome()
159: .readIntention(this , null);
160: return ma.keySet();
161: }
162: }
163:
164: public Set entrySet() {
165: if (!speedoIsActive()) {
166: return accessor.entrySet();
167: } else {
168: MapAccessor ma = (MapAccessor) speedoGetHome()
169: .readIntention(this , null);
170: return ma.entrySet();
171: }
172: }
173:
174: public Collection values() {
175: if (!speedoIsActive()) {
176: return accessor.values();
177: } else {
178: MapAccessor ma = (MapAccessor) speedoGetHome()
179: .readIntention(this, null);
180: return ma.values();
181: }
182: }
183: }
|