KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > myoodb > collectable > LinkedListDbImpl


1 ///////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
4
//
5
// All Rights Reserved
6
//
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License and GNU Library
9
// General Public License as published by the Free Software Foundation;
10
// either version 2, or (at your option) any later version.
11
//
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License and GNU Library General Public License
16
// for more details.
17
//
18
// You should have received a copy of the GNU General Public License
19
// and GNU Library General Public License along with this program; if
20
// not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21
// MA 02139, USA.
22
//
23
///////////////////////////////////////////////////////////////////////////////
24
package org.myoodb.collectable;
25
26 public class LinkedListDbImpl extends CollectableDbImpl implements LinkedList
27 {
28     private java.util.LinkedList JavaDoc m_linkedList;
29
30     public LinkedListDbImpl()
31     {
32         m_linkedList = new java.util.LinkedList JavaDoc();
33     }
34
35     public void fixUpReference(long fixUpTime)
36     {
37         if (referenceHasBeenFixedUp(fixUpTime) == true)
38         {
39             return;
40         }
41
42         super.fixUpReference(fixUpTime);
43
44         synchronized(m_linkedList)
45         {
46             CollectableDbImpl.fixUpReference(m_linkedList, fixUpTime);
47         }
48     }
49
50     public void add(int index, Object JavaDoc element)
51     {
52         synchronized(m_linkedList)
53         {
54             m_linkedList.add(index, element);
55         }
56     }
57
58     public boolean add(Object JavaDoc o)
59     {
60         boolean retval = false;
61
62         synchronized(m_linkedList)
63         {
64             retval = m_linkedList.add(o);
65         }
66
67         return retval;
68     }
69
70     public boolean addAll(java.util.Collection JavaDoc c)
71     {
72         boolean retval = false;
73
74         synchronized(m_linkedList)
75         {
76             retval = m_linkedList.addAll(c);
77         }
78
79         return retval;
80     }
81
82     public boolean addAll(int index, java.util.Collection JavaDoc c)
83     {
84         boolean retval = false;
85
86         synchronized(m_linkedList)
87         {
88             retval = m_linkedList.addAll(index, c);
89         }
90
91         return retval;
92     }
93
94     public void addFirst(Object JavaDoc o)
95     {
96         synchronized(m_linkedList)
97         {
98             m_linkedList.addFirst(o);
99         }
100     }
101
102     public void addLast(Object JavaDoc o)
103     {
104         synchronized(m_linkedList)
105         {
106             m_linkedList.addLast(o);
107         }
108     }
109
110     public Object JavaDoc set(int index, Object JavaDoc element)
111     {
112         Object JavaDoc retval = null;
113
114         synchronized(m_linkedList)
115         {
116             retval = m_linkedList.set(index, element);
117         }
118
119         return retval;
120     }
121
122     public Object JavaDoc get(int index)
123     {
124         return m_linkedList.get(index);
125     }
126
127     public Object JavaDoc get(Object JavaDoc o)
128     {
129         Object JavaDoc retval = null;
130
131         synchronized(m_linkedList)
132         {
133             java.util.Iterator JavaDoc iter = m_linkedList.iterator();
134             while (iter.hasNext())
135             {
136                Object JavaDoc obj = iter.next();
137
138                if (o.equals(obj) == true)
139                {
140                    retval = obj;
141                    break;
142                }
143             }
144         }
145
146         return retval;
147     }
148
149     public Object JavaDoc getWithInverseEqual(Object JavaDoc o)
150     {
151         Object JavaDoc retval = null;
152
153         synchronized(m_linkedList)
154         {
155             java.util.Iterator JavaDoc iter = m_linkedList.iterator();
156             while (iter.hasNext())
157             {
158                Object JavaDoc obj = iter.next();
159
160                if (obj.equals(o) == true)
161                {
162                    retval = obj;
163                    break;
164                }
165             }
166         }
167
168         return retval;
169     }
170
171     public Object JavaDoc getFirst()
172     {
173         Object JavaDoc retval = null;
174
175         synchronized(m_linkedList)
176         {
177             retval = m_linkedList.getFirst();
178         }
179
180         return retval;
181     }
182
183     public Object JavaDoc getLast()
184     {
185         Object JavaDoc retval = null;
186
187         synchronized(m_linkedList)
188         {
189             retval = m_linkedList.getLast();
190         }
191
192         return retval;
193     }
194
195     public boolean contains(Object JavaDoc o)
196     {
197         boolean retval = false;
198
199         synchronized(m_linkedList)
200         {
201             retval = m_linkedList.contains(o);
202         }
203
204         return retval;
205     }
206
207     public boolean containsWithInverseEqual(Object JavaDoc o)
208     {
209         boolean retval = false;
210
211         synchronized(m_linkedList)
212         {
213             java.util.Iterator JavaDoc iter = m_linkedList.iterator();
214             while (iter.hasNext())
215             {
216                Object JavaDoc obj = iter.next();
217
218                if (obj.equals(o) == true)
219                {
220                    retval = true;
221                    break;
222                }
223             }
224         }
225
226         return retval;
227     }
228
229     public int indexOf(Object JavaDoc o)
230     {
231         int retval = -1;
232
233         synchronized(m_linkedList)
234         {
235             retval = m_linkedList.indexOf(o);
236         }
237
238         return retval;
239     }
240
241     public int lastIndexOf(Object JavaDoc o)
242     {
243         int retval = -1;
244
245         synchronized(m_linkedList)
246         {
247             retval = m_linkedList.lastIndexOf(o);
248         }
249
250         return retval;
251     }
252
253     public Object JavaDoc remove(int index)
254     {
255         Object JavaDoc retval = null;
256
257         synchronized(m_linkedList)
258         {
259             retval = m_linkedList.remove(index);
260         }
261
262         return retval;
263     }
264
265     public boolean remove(Object JavaDoc o)
266     {
267         boolean retval = false;
268
269         synchronized(m_linkedList)
270         {
271             retval = m_linkedList.remove(o);
272         }
273
274         return retval;
275     }
276
277     public boolean removeWithInverseEqual(Object JavaDoc o)
278     {
279         boolean retval = false;
280
281         synchronized(m_linkedList)
282         {
283             java.util.Iterator JavaDoc iter = m_linkedList.iterator();
284             while (iter.hasNext())
285             {
286                Object JavaDoc obj = iter.next();
287
288                if (obj.equals(o) == true)
289                {
290                    retval = true;
291                    iter.remove();
292                    break;
293                }
294             }
295         }
296
297         return retval;
298     }
299
300     public Object JavaDoc removeFirst()
301     {
302         Object JavaDoc retval = null;
303
304         synchronized(m_linkedList)
305         {
306             retval = m_linkedList.removeFirst();
307         }
308
309         return retval;
310     }
311
312     public Object JavaDoc removeLast()
313     {
314         Object JavaDoc retval = null;
315
316         synchronized(m_linkedList)
317         {
318             retval = m_linkedList.removeLast();
319         }
320
321         return retval;
322     }
323
324     public void clear()
325     {
326         synchronized(m_linkedList)
327         {
328             m_linkedList.clear();
329         }
330     }
331
332     public int size()
333     {
334         int retval = -1;
335
336         synchronized(m_linkedList)
337         {
338             retval = m_linkedList.size();
339         }
340
341         return retval;
342     }
343
344     public String JavaDoc toString()
345     {
346         String JavaDoc retval = null;
347
348         synchronized(m_linkedList)
349         {
350             retval = m_linkedList.toString();
351         }
352
353         return retval;
354     }
355
356     public boolean equals(Object JavaDoc obj)
357     {
358         boolean retval = false;
359
360         synchronized(m_linkedList)
361         {
362             retval = m_linkedList.equals(obj);
363         }
364
365         return retval;
366     }
367
368     public int hashCode()
369     {
370         int retval = -1;
371
372         synchronized(m_linkedList)
373         {
374             retval = m_linkedList.hashCode();
375         }
376
377         return retval;
378     }
379
380     public java.util.LinkedList JavaDoc collection()
381     {
382         return m_linkedList;
383     }
384
385     public java.util.ArrayList JavaDoc toArrayList()
386     {
387         java.util.ArrayList JavaDoc retval = null;
388
389         synchronized(m_linkedList)
390         {
391             retval = new java.util.ArrayList JavaDoc(m_linkedList);
392         }
393
394         return retval;
395     }
396
397     public Iterator iterator()
398     {
399         return (Iterator) getDatabase().createObject(IteratorDbImpl.class.getName(), "java.util.Collection", new Object JavaDoc[] {m_linkedList});
400     }
401 }
402
Free Books   Free Magazines  
Popular Tags