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.collection;
018:
019: import org.objectweb.speedo.mim.api.StateItf;
020: import org.objectweb.speedo.genclass.api.SpeedoGenClassPO;
021: import java.util.Collection;
022: import java.util.HashSet;
023: import java.util.Iterator;
024:
025: /**
026: *
027: * @author S.Chassande-Barrioz
028: */
029: public abstract class HashSetImpl extends HashSet implements
030: SpeedoGenClassPO {
031:
032: public HashSetImpl() {
033: super ();
034: accessor = (SetAccessor) speedoCreateState();
035: }
036:
037: SetAccessor accessor;
038:
039: public StateItf speedoGetReferenceState() {
040: return accessor;
041: }
042:
043: public void speedoSetReferenceState(StateItf refAcc) {
044: accessor = (SetAccessor) refAcc;
045: }
046:
047: // IMPLEMENTS THE HashSet CLASS //
048: //------------------------------//
049:
050: public boolean add(Object o) {
051: boolean result;
052: if (!speedoIsActive()) {
053: result = accessor.add(o);
054: } else {
055: SetAccessor ca = (SetAccessor) speedoGetHome()
056: .writeIntention(this , null);
057: result = ca.add(o);
058: }
059: return result;
060: }
061:
062: public boolean addAll(Collection c) {
063: boolean result;
064: if (!speedoIsActive()) {
065: result = accessor.addAll(c);
066: } else {
067: SetAccessor ca = (SetAccessor) speedoGetHome()
068: .writeIntention(this , null);
069: result = ca.addAll(c);
070: }
071: return result;
072: }
073:
074: public void clear() {
075: if (!speedoIsActive()) {
076: accessor.clear();
077: } else {
078: SetAccessor ca = (SetAccessor) speedoGetHome()
079: .writeIntention(this , null);
080: ca.clear();
081: }
082: }
083:
084: public boolean contains(Object o) {
085: if (!speedoIsActive()) {
086: return accessor.contains(o);
087: } else {
088: SetAccessor ca = (SetAccessor) speedoGetHome()
089: .readIntention(this , null);
090: return ca.contains(o);
091: }
092: }
093:
094: public boolean containsAll(Collection c) {
095: if (!speedoIsActive()) {
096: return accessor.containsAll(c);
097: } else {
098: SetAccessor ca = (SetAccessor) speedoGetHome()
099: .readIntention(this , null);
100: return ca.containsAll(c);
101: }
102: }
103:
104: public boolean equals(Object o) {
105: if (!speedoIsActive()) {
106: return accessor.equals(o);
107: } else {
108: SetAccessor ca = (SetAccessor) speedoGetHome()
109: .readIntention(this , null);
110: return ca.equals(o);
111: }
112: }
113:
114: public boolean isEmpty() {
115: if (!speedoIsActive()) {
116: return accessor.isEmpty();
117: } else {
118: SetAccessor ca = (SetAccessor) speedoGetHome()
119: .readIntention(this , null);
120: return ca.isEmpty();
121: }
122: }
123:
124: public Iterator iterator() {
125: if (!speedoIsActive()) {
126: return accessor.iterator();
127: } else {
128: SetAccessor ca = (SetAccessor) speedoGetHome()
129: .readIntention(this , null);
130: return ca.iterator();
131: }
132: }
133:
134: public boolean remove(Object o) {
135: boolean result;
136: if (!speedoIsActive()) {
137: result = accessor.remove(o);
138: } else {
139: SetAccessor ca = (SetAccessor) speedoGetHome()
140: .writeIntention(this , null);
141: result = ca.remove(o);
142: }
143: return result;
144: }
145:
146: public boolean removeAll(Collection c) {
147: boolean result;
148: if (!speedoIsActive()) {
149: result = accessor.removeAll(c);
150: } else {
151: SetAccessor ca = (SetAccessor) speedoGetHome()
152: .writeIntention(this , null);
153: result = ca.removeAll(c);
154: }
155: return result;
156: }
157:
158: public boolean retainAll(Collection c) {
159: throw new UnsupportedOperationException();
160: }
161:
162: public int size() {
163: if (!speedoIsActive()) {
164: return accessor.size();
165: } else {
166: SetAccessor ca = (SetAccessor) speedoGetHome()
167: .readIntention(this , null);
168: return ca.size();
169: }
170: }
171:
172: public Object[] toArray() {
173: if (!speedoIsActive()) {
174: return accessor.toArray();
175: } else {
176: SetAccessor ca = (SetAccessor) speedoGetHome()
177: .readIntention(this , null);
178: return ca.toArray();
179: }
180: }
181:
182: public Object[] toArray(Object[] a) {
183: if (!speedoIsActive()) {
184: return accessor.toArray(a);
185: } else {
186: SetAccessor ca = (SetAccessor) speedoGetHome()
187: .readIntention(this , null);
188: return ca.toArray(a);
189: }
190: }
191:
192: // IMPLEMENTS THE SpeedoGenClassPO INTERFACE //
193: //----------------------------------------------//
194:
195: public Object createGenClass() {
196: return new HashSet();
197: }
198:
199: public StateItf speedoCreateState() {
200: return new SetAccessor(this);
201: }
202: }
|