KickJava   Java API By Example, From Geeks To Geeks.

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


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.LinkedList 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 LinkedListImpl extends LinkedList JavaDoc
34         implements SpeedoGenClassProxy {
35
36     public LinkedListImpl() {
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 LinkedList 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 void addFirst(Object JavaDoc o) {
199         if (!jdoIsActive()) {
200             accessor.add(0, o);
201         } else {
202             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
203             ca.add(0, o);
204         }
205     }
206     public void addLast(Object JavaDoc o) {
207         if (!jdoIsActive()) {
208             accessor.add(o);
209         } else {
210             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
211             ca.add(o);
212         }
213     }
214     public Object JavaDoc get(int index) {
215         if (!jdoIsActive()) {
216             return accessor.get(index);
217         } else {
218             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
219             return ca.get(index);
220         }
221     }
222     public int indexOf(Object JavaDoc elem) {
223         if (!jdoIsActive()) {
224             return accessor.indexOf(elem);
225         } else {
226             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
227             return ca.indexOf(elem);
228         }
229     }
230     public Object JavaDoc remove(int index) {
231         if (!jdoIsActive()) {
232             return accessor.remove(index);
233         } else {
234             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
235             return ca.remove(index);
236         }
237     }
238     public Object JavaDoc set(int index, Object JavaDoc element) {
239         if (!jdoIsActive()) {
240             return accessor.set(index, element);
241         } else {
242             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
243             return ca.set(index, element);
244         }
245     }
246     public int lastIndexOf(Object JavaDoc o) {
247         if (!jdoIsActive()) {
248             return accessor.lastIndexOf(o);
249         } else {
250             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
251             return ca.lastIndexOf(o);
252         }
253     }
254     public ListIterator JavaDoc listIterator() {
255         if (!jdoIsActive()) {
256             return ((List JavaDoc) accessor.collection).listIterator();
257         } else {
258             ListAccessor la = (ListAccessor) getSpeedoHome().readIntention(this, null);
259             return la.listIterator();
260         }
261     }
262
263     public ListIterator JavaDoc listIterator(int i) {
264         if (!jdoIsActive()) {
265             return ((List JavaDoc) accessor.collection).listIterator(i);
266         } else {
267             ListAccessor la = (ListAccessor) getSpeedoHome().readIntention(this, null);
268             return la.listIterator(i);
269         }
270     }
271
272     public List JavaDoc subList(int i, int i1) {
273         if (!jdoIsActive()) {
274             return ((List JavaDoc) accessor.collection).subList(i, i1);
275         } else {
276             ListAccessor la = (ListAccessor) getSpeedoHome().readIntention(this, null);
277             return la.subList(i, i1);
278         }
279     }
280     public Object JavaDoc getFirst() {
281         return get(0);
282     }
283     public Object JavaDoc getLast() {
284         if (!jdoIsActive()) {
285             return accessor.get(accessor.size() - 1);
286         } else {
287             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
288             return ca.get(ca.size() - 1);
289         }
290     }
291     public Object JavaDoc removeFirst() {
292         return remove(0);
293     }
294     public Object JavaDoc removeLast() {
295         if (!jdoIsActive()) {
296             return accessor.remove(accessor.size() - 1);
297         } else {
298             ListAccessor ca = (ListAccessor) getSpeedoHome().readIntention(this, null);
299             return ca.remove(ca.size() - 1);
300         }
301     }
302     public Object JavaDoc createGenClass() {
303         return new LinkedList JavaDoc();
304     }
305
306     public SpeedoAccessor createAccessor() {
307         return new ListAccessor(this);
308     }
309 }
310
Popular Tags