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.genclass.api.SpeedoGenClassPO;
020: import org.objectweb.speedo.mim.api.StateItf;
021:
022: import java.util.Collection;
023: import java.util.Iterator;
024: import java.util.ArrayList;
025: import java.util.List;
026: import java.util.ListIterator;
027:
028: /**
029: *
030: * @author S.Chassande-Barrioz
031: */
032: public abstract class ArrayListImpl extends ArrayList implements
033: SpeedoGenClassPO {
034:
035: public ArrayListImpl() {
036: super ();
037: accessor = (ListAccessor) speedoCreateState();
038: }
039:
040: ListAccessor accessor;
041:
042: public StateItf speedoGetReferenceState() {
043: return accessor;
044: }
045:
046: public void speedoSetReferenceState(StateItf refAcc) {
047: accessor = (ListAccessor) refAcc;
048: }
049:
050: // IMPLEMENTS THE HashSet CLASS //
051: //------------------------------//
052:
053: public boolean add(Object o) {
054: boolean result;
055: if (!speedoIsActive()) {
056: result = accessor.add(o);
057: } else {
058: ListAccessor ca = (ListAccessor) speedoGetHome()
059: .writeIntention(this , null);
060: result = ca.add(o);
061: }
062: return result;
063: }
064:
065: public boolean addAll(Collection c) {
066: boolean result;
067: if (!speedoIsActive()) {
068: result = accessor.addAll(c);
069: } else {
070: ListAccessor ca = (ListAccessor) speedoGetHome()
071: .writeIntention(this , null);
072: result = ca.addAll(c);
073: }
074: return result;
075: }
076:
077: public void clear() {
078: if (!speedoIsActive()) {
079: accessor.clear();
080: } else {
081: ListAccessor ca = (ListAccessor) speedoGetHome()
082: .writeIntention(this , null);
083: ca.clear();
084: }
085: }
086:
087: public boolean contains(Object o) {
088: if (!speedoIsActive()) {
089: return accessor.contains(o);
090: } else {
091: ListAccessor ca = (ListAccessor) speedoGetHome()
092: .readIntention(this , null);
093: return ca.contains(o);
094: }
095: }
096:
097: public boolean containsAll(Collection c) {
098: if (!speedoIsActive()) {
099: return accessor.containsAll(c);
100: } else {
101: ListAccessor ca = (ListAccessor) speedoGetHome()
102: .readIntention(this , null);
103: return ca.containsAll(c);
104: }
105: }
106:
107: public boolean equals(Object o) {
108: if (!speedoIsActive()) {
109: return accessor.equals(o);
110: } else {
111: ListAccessor ca = (ListAccessor) speedoGetHome()
112: .readIntention(this , null);
113: return ca.equals(o);
114: }
115: }
116:
117: public boolean isEmpty() {
118: if (!speedoIsActive()) {
119: return accessor.isEmpty();
120: } else {
121: ListAccessor ca = (ListAccessor) speedoGetHome()
122: .readIntention(this , null);
123: return ca.isEmpty();
124: }
125: }
126:
127: public Iterator iterator() {
128: if (!speedoIsActive()) {
129: return accessor.iterator();
130: } else {
131: ListAccessor ca = (ListAccessor) speedoGetHome()
132: .readIntention(this , null);
133: return ca.iterator();
134: }
135: }
136:
137: public boolean remove(Object o) {
138: boolean result;
139: if (!speedoIsActive()) {
140: result = accessor.remove(o);
141: } else {
142: ListAccessor ca = (ListAccessor) speedoGetHome()
143: .writeIntention(this , null);
144: result = ca.remove(o);
145: }
146: return result;
147: }
148:
149: public boolean removeAll(Collection c) {
150: boolean result;
151: if (!speedoIsActive()) {
152: result = accessor.removeAll(c);
153: } else {
154: ListAccessor ca = (ListAccessor) speedoGetHome()
155: .writeIntention(this , null);
156: result = ca.removeAll(c);
157: }
158: return result;
159: }
160:
161: public boolean retainAll(Collection c) {
162: throw new UnsupportedOperationException();
163: }
164:
165: public int size() {
166: if (!speedoIsActive()) {
167: return accessor.size();
168: } else {
169: ListAccessor ca = (ListAccessor) speedoGetHome()
170: .readIntention(this , null);
171: return ca.size();
172: }
173: }
174:
175: public Object[] toArray() {
176: if (!speedoIsActive()) {
177: return accessor.toArray();
178: } else {
179: ListAccessor ca = (ListAccessor) speedoGetHome()
180: .readIntention(this , null);
181: return ca.toArray();
182: }
183: }
184:
185: public Object[] toArray(Object[] a) {
186: if (!speedoIsActive()) {
187: return accessor.toArray(a);
188: } else {
189: ListAccessor ca = (ListAccessor) speedoGetHome()
190: .readIntention(this , null);
191: return ca.toArray(a);
192: }
193: }
194:
195: public void add(int index, Object element) {
196: if (!speedoIsActive()) {
197: accessor.add(index, element);
198: } else {
199: ListAccessor ca = (ListAccessor) speedoGetHome()
200: .readIntention(this , null);
201: ca.add(index, element);
202: }
203: }
204:
205: public boolean addAll(int index, Collection c) {
206: if (!speedoIsActive()) {
207: return accessor.addAll(index, c);
208: } else {
209: ListAccessor ca = (ListAccessor) speedoGetHome()
210: .readIntention(this , null);
211: return ca.addAll(index, c);
212: }
213: }
214:
215: public Object get(int index) {
216: if (!speedoIsActive()) {
217: return accessor.get(index);
218: } else {
219: ListAccessor ca = (ListAccessor) speedoGetHome()
220: .readIntention(this , null);
221: return ca.get(index);
222: }
223: }
224:
225: public int indexOf(Object elem) {
226: if (!speedoIsActive()) {
227: return accessor.indexOf(elem);
228: } else {
229: ListAccessor ca = (ListAccessor) speedoGetHome()
230: .readIntention(this , null);
231: return ca.indexOf(elem);
232: }
233: }
234:
235: public Object remove(int index) {
236: if (!speedoIsActive()) {
237: return accessor.remove(index);
238: } else {
239: ListAccessor ca = (ListAccessor) speedoGetHome()
240: .readIntention(this , null);
241: return ca.remove(index);
242: }
243: }
244:
245: public Object set(int index, Object element) {
246: if (!speedoIsActive()) {
247: return accessor.set(index, element);
248: } else {
249: ListAccessor ca = (ListAccessor) speedoGetHome()
250: .readIntention(this , null);
251: return ca.set(index, element);
252: }
253: }
254:
255: public int lastIndexOf(Object o) {
256: if (!speedoIsActive()) {
257: return accessor.lastIndexOf(o);
258: } else {
259: ListAccessor ca = (ListAccessor) speedoGetHome()
260: .readIntention(this , null);
261: return ca.lastIndexOf(o);
262: }
263: }
264:
265: public ListIterator listIterator() {
266: if (!speedoIsActive()) {
267: return ((List) accessor.collection).listIterator();
268: } else {
269: ListAccessor la = (ListAccessor) speedoGetHome()
270: .readIntention(this , null);
271: return la.listIterator();
272: }
273: }
274:
275: public ListIterator listIterator(int i) {
276: if (!speedoIsActive()) {
277: return ((List) accessor.collection).listIterator(i);
278: } else {
279: ListAccessor la = (ListAccessor) speedoGetHome()
280: .readIntention(this , null);
281: return la.listIterator(i);
282: }
283: }
284:
285: public List subList(int i, int i1) {
286: if (!speedoIsActive()) {
287: return ((List) accessor.collection).subList(i, i1);
288: } else {
289: ListAccessor la = (ListAccessor) speedoGetHome()
290: .readIntention(this , null);
291: return la.subList(i, i1);
292: }
293: }
294:
295: public Object createGenClass() {
296: return new ArrayList();
297: }
298:
299: public StateItf speedoCreateState() {
300: return new ListAccessor(this);
301: }
302: }
|