001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.db4ounit.jre12.collections;
022:
023: import java.util.*;
024:
025: import com.db4o.foundation.*;
026: import com.db4o.internal.collections.*;
027:
028: public class MockPersistentList implements PersistentList {
029:
030: private Vector _vector = new Vector();
031:
032: public boolean add(Object o) {
033: return _vector.add(o);
034: }
035:
036: public void add(int index, Object element) {
037: _vector.add(index, element);
038: }
039:
040: public boolean addAll(Iterable4 i) {
041: Iterator4 iterator = i.iterator();
042: while (iterator.moveNext()) {
043: add(iterator.current());
044: }
045: return true;
046: }
047:
048: public boolean addAll(int index, Iterable4 i) {
049: Iterator4 iterator = i.iterator();
050: while (iterator.moveNext()) {
051: add(index++, iterator.current());
052: }
053: return true;
054: }
055:
056: public void clear() {
057: _vector.clear();
058: }
059:
060: public boolean contains(Object o) {
061: return _vector.contains(o);
062: }
063:
064: public boolean containsAll(Iterable4 i) {
065: Iterator4 iterator = i.iterator();
066: while (iterator.moveNext()) {
067: if (!contains(iterator.current())) {
068: return false;
069: }
070: }
071: return true;
072: }
073:
074: public Object get(int index) {
075: return _vector.get(index);
076: }
077:
078: public int indexOf(Object o) {
079: return _vector.indexOf(o);
080: }
081:
082: public boolean isEmpty() {
083: return _vector.isEmpty();
084: }
085:
086: public Iterator4 iterator() {
087: return new Collection4(_vector.toArray()).iterator();
088: }
089:
090: public int lastIndexOf(Object o) {
091: return _vector.lastIndexOf(o);
092: }
093:
094: public boolean remove(Object o) {
095: return _vector.remove(o);
096: }
097:
098: public Object remove(int index) {
099: return _vector.remove(index);
100: }
101:
102: public boolean removeAll(Iterable4 i) {
103: boolean result = false;
104: Iterator4 iterator = i.iterator();
105: while (iterator.moveNext()) {
106: if (remove(iterator.current())) {
107: result = true;
108: }
109: }
110: return result;
111: }
112:
113: public boolean retainAll(Iterable4 retained) {
114: boolean result = false;
115: Iterator iter = _vector.iterator();
116: while (iter.hasNext()) {
117: if (!contains(retained, iter.next())) {
118: iter.remove();
119: result = true;
120: }
121: }
122: return result;
123: }
124:
125: private boolean contains(Iterable4 iter, Object element) {
126: Iterator4 i = iter.iterator();
127: while (i.moveNext()) {
128: Object current = i.current();
129: if ((current == null && element == null)
130: || current.equals(element)) {
131: return true;
132: }
133: }
134: return false;
135: }
136:
137: public Object set(int index, Object element) {
138: return _vector.set(index, element);
139: }
140:
141: public int size() {
142: return _vector.size();
143: }
144:
145: public PersistentList subList(int fromIndex, int toIndex) {
146: throw new NotImplementedException();
147: }
148:
149: public Object[] toArray() {
150: return _vector.toArray();
151: }
152:
153: public Object[] toArray(Object[] a) {
154: return _vector.toArray(a);
155: }
156:
157: }
|