001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
004: //
005: // All Rights Reserved
006: //
007: // This program is free software; you can redistribute it and/or modify
008: // it under the terms of the GNU General Public License and GNU Library
009: // General Public License as published by the Free Software Foundation;
010: // either version 2, or (at your option) any later version.
011: //
012: // This program is distributed in the hope that it will be useful,
013: // but WITHOUT ANY WARRANTY; without even the implied warranty of
014: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: // GNU General Public License and GNU Library General Public License
016: // for more details.
017: //
018: // You should have received a copy of the GNU General Public License
019: // and GNU Library General Public License along with this program; if
020: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
021: // MA 02139, USA.
022: //
023: ///////////////////////////////////////////////////////////////////////////////
024: package org.myoodb.collectable;
025:
026: public class LinkedListDbImpl extends CollectableDbImpl implements
027: LinkedList {
028: private java.util.LinkedList m_linkedList;
029:
030: public LinkedListDbImpl() {
031: m_linkedList = new java.util.LinkedList();
032: }
033:
034: public void fixUpReference(long fixUpTime) {
035: if (referenceHasBeenFixedUp(fixUpTime) == true) {
036: return;
037: }
038:
039: super .fixUpReference(fixUpTime);
040:
041: synchronized (m_linkedList) {
042: CollectableDbImpl.fixUpReference(m_linkedList, fixUpTime);
043: }
044: }
045:
046: public void add(int index, Object element) {
047: synchronized (m_linkedList) {
048: m_linkedList.add(index, element);
049: }
050: }
051:
052: public boolean add(Object o) {
053: boolean retval = false;
054:
055: synchronized (m_linkedList) {
056: retval = m_linkedList.add(o);
057: }
058:
059: return retval;
060: }
061:
062: public boolean addAll(java.util.Collection c) {
063: boolean retval = false;
064:
065: synchronized (m_linkedList) {
066: retval = m_linkedList.addAll(c);
067: }
068:
069: return retval;
070: }
071:
072: public boolean addAll(int index, java.util.Collection c) {
073: boolean retval = false;
074:
075: synchronized (m_linkedList) {
076: retval = m_linkedList.addAll(index, c);
077: }
078:
079: return retval;
080: }
081:
082: public void addFirst(Object o) {
083: synchronized (m_linkedList) {
084: m_linkedList.addFirst(o);
085: }
086: }
087:
088: public void addLast(Object o) {
089: synchronized (m_linkedList) {
090: m_linkedList.addLast(o);
091: }
092: }
093:
094: public Object set(int index, Object element) {
095: Object retval = null;
096:
097: synchronized (m_linkedList) {
098: retval = m_linkedList.set(index, element);
099: }
100:
101: return retval;
102: }
103:
104: public Object get(int index) {
105: return m_linkedList.get(index);
106: }
107:
108: public Object get(Object o) {
109: Object retval = null;
110:
111: synchronized (m_linkedList) {
112: java.util.Iterator iter = m_linkedList.iterator();
113: while (iter.hasNext()) {
114: Object obj = iter.next();
115:
116: if (o.equals(obj) == true) {
117: retval = obj;
118: break;
119: }
120: }
121: }
122:
123: return retval;
124: }
125:
126: public Object getWithInverseEqual(Object o) {
127: Object retval = null;
128:
129: synchronized (m_linkedList) {
130: java.util.Iterator iter = m_linkedList.iterator();
131: while (iter.hasNext()) {
132: Object obj = iter.next();
133:
134: if (obj.equals(o) == true) {
135: retval = obj;
136: break;
137: }
138: }
139: }
140:
141: return retval;
142: }
143:
144: public Object getFirst() {
145: Object retval = null;
146:
147: synchronized (m_linkedList) {
148: retval = m_linkedList.getFirst();
149: }
150:
151: return retval;
152: }
153:
154: public Object getLast() {
155: Object retval = null;
156:
157: synchronized (m_linkedList) {
158: retval = m_linkedList.getLast();
159: }
160:
161: return retval;
162: }
163:
164: public boolean contains(Object o) {
165: boolean retval = false;
166:
167: synchronized (m_linkedList) {
168: retval = m_linkedList.contains(o);
169: }
170:
171: return retval;
172: }
173:
174: public boolean containsWithInverseEqual(Object o) {
175: boolean retval = false;
176:
177: synchronized (m_linkedList) {
178: java.util.Iterator iter = m_linkedList.iterator();
179: while (iter.hasNext()) {
180: Object obj = iter.next();
181:
182: if (obj.equals(o) == true) {
183: retval = true;
184: break;
185: }
186: }
187: }
188:
189: return retval;
190: }
191:
192: public int indexOf(Object o) {
193: int retval = -1;
194:
195: synchronized (m_linkedList) {
196: retval = m_linkedList.indexOf(o);
197: }
198:
199: return retval;
200: }
201:
202: public int lastIndexOf(Object o) {
203: int retval = -1;
204:
205: synchronized (m_linkedList) {
206: retval = m_linkedList.lastIndexOf(o);
207: }
208:
209: return retval;
210: }
211:
212: public Object remove(int index) {
213: Object retval = null;
214:
215: synchronized (m_linkedList) {
216: retval = m_linkedList.remove(index);
217: }
218:
219: return retval;
220: }
221:
222: public boolean remove(Object o) {
223: boolean retval = false;
224:
225: synchronized (m_linkedList) {
226: retval = m_linkedList.remove(o);
227: }
228:
229: return retval;
230: }
231:
232: public boolean removeWithInverseEqual(Object o) {
233: boolean retval = false;
234:
235: synchronized (m_linkedList) {
236: java.util.Iterator iter = m_linkedList.iterator();
237: while (iter.hasNext()) {
238: Object obj = iter.next();
239:
240: if (obj.equals(o) == true) {
241: retval = true;
242: iter.remove();
243: break;
244: }
245: }
246: }
247:
248: return retval;
249: }
250:
251: public Object removeFirst() {
252: Object retval = null;
253:
254: synchronized (m_linkedList) {
255: retval = m_linkedList.removeFirst();
256: }
257:
258: return retval;
259: }
260:
261: public Object removeLast() {
262: Object retval = null;
263:
264: synchronized (m_linkedList) {
265: retval = m_linkedList.removeLast();
266: }
267:
268: return retval;
269: }
270:
271: public void clear() {
272: synchronized (m_linkedList) {
273: m_linkedList.clear();
274: }
275: }
276:
277: public int size() {
278: int retval = -1;
279:
280: synchronized (m_linkedList) {
281: retval = m_linkedList.size();
282: }
283:
284: return retval;
285: }
286:
287: public String toString() {
288: String retval = null;
289:
290: synchronized (m_linkedList) {
291: retval = m_linkedList.toString();
292: }
293:
294: return retval;
295: }
296:
297: public boolean equals(Object obj) {
298: boolean retval = false;
299:
300: synchronized (m_linkedList) {
301: retval = m_linkedList.equals(obj);
302: }
303:
304: return retval;
305: }
306:
307: public int hashCode() {
308: int retval = -1;
309:
310: synchronized (m_linkedList) {
311: retval = m_linkedList.hashCode();
312: }
313:
314: return retval;
315: }
316:
317: public java.util.LinkedList collection() {
318: return m_linkedList;
319: }
320:
321: public java.util.ArrayList toArrayList() {
322: java.util.ArrayList retval = null;
323:
324: synchronized (m_linkedList) {
325: retval = new java.util.ArrayList(m_linkedList);
326: }
327:
328: return retval;
329: }
330:
331: public Iterator iterator() {
332: return (Iterator) getDatabase().createObject(
333: IteratorDbImpl.class.getName(), "java.util.Collection",
334: new Object[] { m_linkedList });
335: }
336: }
|