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:
021: import java.util.List;
022: import java.util.Collection;
023: import java.util.Iterator;
024: import java.util.ListIterator;
025: import java.util.ArrayList;
026:
027: /**
028: *
029: * @author S.Chassande-Barrioz
030: */
031: public class ListImpl extends CollectionImpl implements List {
032:
033: /**
034: * Instantiates a new collection.
035: */
036: public ListImpl() {
037: super ();
038: }
039:
040: // IMPLEMENTATION OF THE GenClass ABSTRACT CLASS //
041: //-----------------------------------------------//
042:
043: public StateItf speedoCreateState() {
044: return new ListAccessor(this );
045: }
046:
047: public Object createGenClass() {
048: return new ArrayList();
049: }
050:
051: // IMPLEMENTATION OF THE List INTERFACE //
052: //--------------------------------------//
053:
054: public boolean addAll(int i, Collection collection) {
055: if (collection == null) {
056: return true;
057: }
058: int idx = i;
059: Iterator it = collection.iterator();
060: while (it.hasNext()) {
061: add(idx, it.next());
062: idx++;
063: }
064: return idx > i;
065: }
066:
067: public Object get(int i) {
068: if (!speedoIsActive) {
069: return ((List) accessor.collection).get(i);
070: } else {
071: ListAccessor la = (ListAccessor) speedoGetHome()
072: .readIntention(this , null);
073: return la.get(i);
074: }
075: }
076:
077: public Object set(int i, Object o) {
078: if (!speedoIsActive) {
079: return ((List) accessor.collection).set(i, o);
080: } else {
081: ListAccessor la = (ListAccessor) speedoGetHome()
082: .writeIntention(this , null);
083: return la.set(i, o);
084: }
085: }
086:
087: public void add(int i, Object o) {
088: if (!speedoIsActive) {
089: ((List) accessor.collection).add(i, o);
090: } else {
091: ListAccessor la = (ListAccessor) speedoGetHome()
092: .writeIntention(this , null);
093: la.add(i, o);
094: }
095: }
096:
097: public Object remove(int i) {
098: if (!speedoIsActive) {
099: return ((List) accessor.collection).remove(i);
100: } else {
101: ListAccessor la = (ListAccessor) speedoGetHome()
102: .writeIntention(this , null);
103: return la.remove(i);
104: }
105: }
106:
107: public int indexOf(Object o) {
108: if (!speedoIsActive) {
109: return ((List) accessor.collection).indexOf(o);
110: } else {
111: ListAccessor la = (ListAccessor) speedoGetHome()
112: .readIntention(this , null);
113: return la.indexOf(o);
114: }
115: }
116:
117: public int lastIndexOf(Object o) {
118: if (!speedoIsActive) {
119: return ((List) accessor.collection).lastIndexOf(o);
120: } else {
121: ListAccessor la = (ListAccessor) speedoGetHome()
122: .readIntention(this , null);
123: return la.lastIndexOf(o);
124: }
125: }
126:
127: public ListIterator listIterator() {
128: if (!speedoIsActive) {
129: return ((List) accessor.collection).listIterator();
130: } else {
131: ListAccessor la = (ListAccessor) speedoGetHome()
132: .readIntention(this , null);
133: return la.listIterator();
134: }
135: }
136:
137: public ListIterator listIterator(int i) {
138: if (!speedoIsActive) {
139: return ((List) accessor.collection).listIterator(i);
140: } else {
141: ListAccessor la = (ListAccessor) speedoGetHome()
142: .readIntention(this , null);
143: return la.listIterator(i);
144: }
145: }
146:
147: public List subList(int i, int i1) {
148: if (!speedoIsActive) {
149: return ((List) accessor.collection).subList(i, i1);
150: } else {
151: ListAccessor la = (ListAccessor) speedoGetHome()
152: .readIntention(this, null);
153: return la.subList(i, i1);
154: }
155: }
156:
157: }
|