KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > genclass > collection > ArrayListImpl


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.collection;
19
20 import org.objectweb.speedo.genclass.api.SpeedoGenClassProxy;
21 import org.objectweb.speedo.mim.api.SpeedoAccessor;
22
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.ListIterator JavaDoc;
28
29 /**
30  *
31  * @author S.Chassande-Barrioz
32  */

33 public abstract class ArrayListImpl extends ArrayList JavaDoc
34         implements SpeedoGenClassProxy {
35
36     public ArrayListImpl() {
37         super();
38         accessor = (ListAccessor) createAccessor();
39     }
40
41     ListAccessor accessor;
42
43     public SpeedoAccessor getReferenceAccessor() {
44         return accessor;
45     }
46     public void setReferenceAccessor(SpeedoAccessor refAcc) {
47         accessor = (ListAccessor) refAcc;
48     }
49
50     // IMPLEMENTS THE HashSet CLASS //
51
//------------------------------//
52

53     public boolean add(Object JavaDoc o) {
54         boolean result;
55         if (!jdoIsActive()) {
56             result = accessor.add(o);
57         } else {
58             ListAccessor ca = (ListAccessor) getSpeedoHome().writeIntention(this, null);
59             result = ca.add(o);
60         }
61         return result;
62     }
63
64     public boolean addAll(Collection JavaDoc c) {
65         boolean result;
66         if (!jdoIsActive()) {
67             result = accessor.addAll(c);
68         } else {
69             ListAccessor ca = (ListAccessor) getSpeedoHome().writeIntention(this, null);
70             result = ca.addAll(c);
71         }
72         return result;
73     }
74
75     public void clear() {
76         if (!jdoIsActive()) {
77             accessor.clear();
78         } else {
79             ListAccessor ca = (ListAccessor) getSpeedoHome().writeIntention(this, null);
80             ca.clear();
81         }
82     }
83
84     public boolean contains(Object JavaDoc o) {
85         if (!jdoIsActive()) {
86             return accessor.contains(o);
87         } else {
88             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
89             return ca.contains(o);
90         }
91     }
92
93     public boolean containsAll(Collection JavaDoc c) {
94         if (!jdoIsActive()) {
95             return accessor.containsAll(c);
96         } else {
97             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
98             return ca.containsAll(c);
99         }
100     }
101
102     public boolean equals(Object JavaDoc o) {
103         if (!jdoIsActive()) {
104             return accessor.equals(o);
105         } else {
106             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
107             return ca.equals(o);
108         }
109     }
110
111     public boolean isEmpty() {
112         if (!jdoIsActive()) {
113             return accessor.isEmpty();
114         } else {
115             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
116             return ca.isEmpty();
117         }
118     }
119
120     public Iterator JavaDoc iterator() {
121         if (!jdoIsActive()) {
122             return accessor.iterator();
123         } else {
124             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
125             return ca.iterator();
126         }
127     }
128
129     public boolean remove(Object JavaDoc o) {
130         boolean result;
131         if (!jdoIsActive()) {
132             result = accessor.remove(o);
133         } else {
134             ListAccessor ca = (ListAccessor) getSpeedoHome().writeIntention(this, null);
135             result = ca.remove(o);
136         }
137         return result;
138     }
139
140     public boolean removeAll(Collection JavaDoc c) {
141         boolean result;
142         if (!jdoIsActive()) {
143             result = accessor.removeAll(c);
144         } else {
145             ListAccessor ca = (ListAccessor) getSpeedoHome().writeIntention(this, null);
146             result = ca.removeAll(c);
147         }
148         return result;
149     }
150
151     public boolean retainAll(Collection JavaDoc c) {
152         throw new UnsupportedOperationException JavaDoc();
153     }
154
155     public int size() {
156         if (!jdoIsActive()) {
157             return accessor.size();
158         } else {
159             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
160             return ca.size();
161         }
162     }
163
164     public Object JavaDoc[] toArray() {
165         if (!jdoIsActive()) {
166             return accessor.toArray();
167         } else {
168             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
169             return ca.toArray();
170         }
171     }
172
173     public Object JavaDoc[] toArray(Object JavaDoc[] a) {
174         if (!jdoIsActive()) {
175             return accessor.toArray(a);
176         } else {
177             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
178             return ca.toArray(a);
179         }
180     }
181
182     public void add(int index, Object JavaDoc element) {
183         if (!jdoIsActive()) {
184             accessor.add(index, element);
185         } else {
186             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
187             ca.add(index, element);
188         }
189     }
190     public boolean addAll(int index, Collection JavaDoc c) {
191         if (!jdoIsActive()) {
192             return accessor.addAll(index, c);
193         } else {
194             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
195             return ca.addAll(index, c);
196         }
197     }
198     public Object JavaDoc get(int index) {
199         if (!jdoIsActive()) {
200             return accessor.get(index);
201         } else {
202             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
203             return ca.get(index);
204         }
205     }
206     public int indexOf(Object JavaDoc elem) {
207         if (!jdoIsActive()) {
208             return accessor.indexOf(elem);
209         } else {
210             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
211             return ca.indexOf(elem);
212         }
213     }
214     public Object JavaDoc remove(int index) {
215         if (!jdoIsActive()) {
216             return accessor.remove(index);
217         } else {
218             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
219             return ca.remove(index);
220         }
221     }
222     public Object JavaDoc set(int index, Object JavaDoc element) {
223         if (!jdoIsActive()) {
224             return accessor.set(index, element);
225         } else {
226             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
227             return ca.set(index, element);
228         }
229     }
230     public int lastIndexOf(Object JavaDoc o) {
231         if (!jdoIsActive()) {
232             return accessor.lastIndexOf(o);
233         } else {
234             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
235             return ca.lastIndexOf(o);
236         }
237     }
238     public ListIterator JavaDoc listIterator() {
239         if (!jdoIsActive()) {
240             return ((List JavaDoc) accessor.collection).listIterator();
241         } else {
242             ListAccessor la = (ListAccessor) getSpeedoHome().readIntention(this, null);
243             return la.listIterator();
244         }
245     }
246
247     public ListIterator JavaDoc listIterator(int i) {
248         if (!jdoIsActive()) {
249             return ((List JavaDoc) accessor.collection).listIterator(i);
250         } else {
251             ListAccessor la = (ListAccessor) getSpeedoHome().readIntention(this, null);
252             return la.listIterator(i);
253         }
254     }
255
256     public List JavaDoc subList(int i, int i1) {
257         if (!jdoIsActive()) {
258             return ((List JavaDoc) accessor.collection).subList(i, i1);
259         } else {
260             ListAccessor la = (ListAccessor) getSpeedoHome().readIntention(this, null);
261             return la.subList(i, i1);
262         }
263     }
264     public Object JavaDoc createGenClass() {
265         return new ArrayList JavaDoc();
266     }
267
268     public SpeedoAccessor createAccessor() {
269         return new ListAccessor(this);
270     }
271 }
272
Popular Tags