KickJava   Java API By Example, From Geeks To Geeks.

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


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

32 public class ListImpl extends CollectionImpl implements List JavaDoc {
33
34
35     /**
36      * Instantiates a new collection.
37      */

38     public ListImpl() {
39         super();
40     }
41
42     // IMPLEMENTATION OF THE GenClass ABSTRACT CLASS //
43
//-----------------------------------------------//
44

45     public SpeedoAccessor createAccessor() {
46         return new ListAccessor(this);
47     }
48
49     public Object JavaDoc createGenClass() {
50         return new ArrayList JavaDoc();
51     }
52
53     // IMPLEMENTATION OF THE List INTERFACE //
54
//--------------------------------------//
55

56     public boolean addAll(int i, Collection JavaDoc collection) {
57         if (collection == null) {
58             return true;
59         }
60         int idx = i;
61         Iterator JavaDoc it = collection.iterator();
62         while(it.hasNext()) {
63             add(idx, it.next());
64             idx ++;
65         }
66         return idx > i;
67     }
68
69     public Object JavaDoc get(int i) {
70         if (!jdoIsActive) {
71             return ((List JavaDoc) accessor.collection).get(i);
72         } else {
73             ListAccessor la = (ListAccessor) getSpeedoHome().readIntention(this, null);
74             return la.get(i);
75         }
76     }
77
78     public Object JavaDoc set(int i, Object JavaDoc o) {
79         if (!jdoIsActive) {
80             return ((List JavaDoc) accessor.collection).set(i,o);
81         } else {
82             ListAccessor la = (ListAccessor) getSpeedoHome().writeIntention(this, null);
83             return la.set(i, o);
84         }
85     }
86
87     public void add(int i, Object JavaDoc o) {
88         if (!jdoIsActive) {
89             ((List JavaDoc) accessor.collection).add(i, o);
90         } else {
91             ListAccessor la = (ListAccessor) getSpeedoHome().writeIntention(this, null);
92             la.add(i, o);
93         }
94     }
95
96     public Object JavaDoc remove(int i) {
97         if (!jdoIsActive) {
98             return ((List JavaDoc) accessor.collection).remove(i);
99         } else {
100             ListAccessor la = (ListAccessor) getSpeedoHome().writeIntention(this, null);
101             return la.remove(i);
102         }
103     }
104
105     public int indexOf(Object JavaDoc o) {
106         if (!jdoIsActive) {
107             return ((List JavaDoc) accessor.collection).indexOf(o);
108         } else {
109             ListAccessor la = (ListAccessor) getSpeedoHome().readIntention(this, null);
110             return la.indexOf(o);
111         }
112     }
113
114     public int lastIndexOf(Object JavaDoc o) {
115         if (!jdoIsActive) {
116             return ((List JavaDoc) accessor.collection).lastIndexOf(o);
117         } else {
118             ListAccessor la = (ListAccessor) getSpeedoHome().readIntention(this, null);
119             return la.lastIndexOf(o);
120         }
121     }
122
123     public ListIterator JavaDoc listIterator() {
124         if (!jdoIsActive) {
125             return ((List JavaDoc) accessor.collection).listIterator();
126         } else {
127             ListAccessor la = (ListAccessor) getSpeedoHome().readIntention(this, null);
128             return la.listIterator();
129         }
130     }
131
132     public ListIterator JavaDoc listIterator(int i) {
133         if (!jdoIsActive) {
134             return ((List JavaDoc) accessor.collection).listIterator(i);
135         } else {
136             ListAccessor la = (ListAccessor) getSpeedoHome().readIntention(this, null);
137             return la.listIterator(i);
138         }
139     }
140
141     public List JavaDoc subList(int i, int i1) {
142         if (!jdoIsActive) {
143             return ((List JavaDoc) accessor.collection).subList(i, i1);
144         } else {
145             ListAccessor la = (ListAccessor) getSpeedoHome().readIntention(this, null);
146             return la.subList(i, i1);
147         }
148     }
149
150 }
151
Popular Tags