KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.objectweb.speedo.genclass.api.SpeedoGenClassProxy;
22 import java.util.Collection JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26 /**
27  *
28  * @author S.Chassande-Barrioz
29  */

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

52     public boolean add(Object JavaDoc o) {
53         boolean result;
54         if (!jdoIsActive()) {
55             result = accessor.add(o);
56         } else {
57             SetAccessor ca = (SetAccessor) getSpeedoHome().writeIntention(this, null);
58             result = ca.add(o);
59         }
60         return result;
61     }
62
63     public boolean addAll(Collection JavaDoc c) {
64         boolean result;
65         if (!jdoIsActive()) {
66             result = accessor.addAll(c);
67         } else {
68             SetAccessor ca = (SetAccessor) getSpeedoHome().writeIntention(this, null);
69             result = ca.addAll(c);
70         }
71         return result;
72     }
73
74     public void clear() {
75         if (!jdoIsActive()) {
76             accessor.clear();
77         } else {
78             SetAccessor ca = (SetAccessor) getSpeedoHome().writeIntention(this, null);
79             ca.clear();
80         }
81     }
82
83     public boolean contains(Object JavaDoc o) {
84         if (!jdoIsActive()) {
85             return accessor.contains(o);
86         } else {
87             SetAccessor ca = (SetAccessor) getSpeedoHome().readIntention(this, null);
88             return ca.contains(o);
89         }
90     }
91
92     public boolean containsAll(Collection JavaDoc c) {
93         if (!jdoIsActive()) {
94             return accessor.containsAll(c);
95         } else {
96             SetAccessor ca = (SetAccessor) getSpeedoHome().readIntention(this, null);
97             return ca.containsAll(c);
98         }
99     }
100
101     public boolean equals(Object JavaDoc o) {
102         if (!jdoIsActive()) {
103             return accessor.equals(o);
104         } else {
105             SetAccessor ca = (SetAccessor) getSpeedoHome().readIntention(this, null);
106             return ca.equals(o);
107         }
108     }
109
110     public boolean isEmpty() {
111         if (!jdoIsActive()) {
112             return accessor.isEmpty();
113         } else {
114             SetAccessor ca = (SetAccessor) getSpeedoHome().readIntention(this, null);
115             return ca.isEmpty();
116         }
117     }
118
119     public Iterator JavaDoc iterator() {
120         if (!jdoIsActive()) {
121             return accessor.iterator();
122         } else {
123             SetAccessor ca = (SetAccessor) getSpeedoHome().readIntention(this, null);
124             return ca.iterator();
125         }
126     }
127
128     public boolean remove(Object JavaDoc o) {
129         boolean result;
130         if (!jdoIsActive()) {
131             result = accessor.remove(o);
132         } else {
133             SetAccessor ca = (SetAccessor) getSpeedoHome().writeIntention(this, null);
134             result = ca.remove(o);
135         }
136         return result;
137     }
138
139     public boolean removeAll(Collection JavaDoc c) {
140         boolean result;
141         if (!jdoIsActive()) {
142             result = accessor.removeAll(c);
143         } else {
144             SetAccessor ca = (SetAccessor) getSpeedoHome().writeIntention(this, null);
145             result = ca.removeAll(c);
146         }
147         return result;
148     }
149
150     public boolean retainAll(Collection JavaDoc c) {
151         throw new UnsupportedOperationException JavaDoc();
152     }
153
154     public int size() {
155         if (!jdoIsActive()) {
156             return accessor.size();
157         } else {
158             SetAccessor ca = (SetAccessor) getSpeedoHome().readIntention(this, null);
159             return ca.size();
160         }
161     }
162
163     public Object JavaDoc[] toArray() {
164         if (!jdoIsActive()) {
165             return accessor.toArray();
166         } else {
167             SetAccessor ca = (SetAccessor) getSpeedoHome().readIntention(this, null);
168             return ca.toArray();
169         }
170     }
171
172     public Object JavaDoc[] toArray(Object JavaDoc[] a) {
173         if (!jdoIsActive()) {
174             return accessor.toArray(a);
175         } else {
176             SetAccessor ca = (SetAccessor) getSpeedoHome().readIntention(this, null);
177             return ca.toArray(a);
178         }
179     }
180
181     // IMPLEMENTS THE SpeedoGenClassProxy INTERFACE //
182
//----------------------------------------------//
183

184     public Object JavaDoc createGenClass() {
185         return new HashSet JavaDoc();
186     }
187
188     public SpeedoAccessor createAccessor() {
189         return new SetAccessor(this);
190     }
191 }
192
Popular Tags