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.test.legacy.soda.collections;
022:
023: import java.util.*;
024:
025: import com.db4o.query.*;
026: import com.db4o.test.legacy.soda.*;
027: import com.db4o.test.legacy.soda.collections.*;
028:
029: public class STOwnCollectionT implements STClass {
030:
031: public static transient SodaTest st;
032:
033: MyCollection col;
034:
035: public STOwnCollectionT() {
036:
037: }
038:
039: public STOwnCollectionT(Object[] arr) {
040: col = new MyCollection();
041: for (int i = 0; i < arr.length; i++) {
042: col.add(arr[i]);
043: }
044: }
045:
046: public Object[] store() {
047: return new Object[] {
048: new STOwnCollectionT(),
049: new STOwnCollectionT(new Object[0]),
050: new STOwnCollectionT(new Object[] { new Integer(0),
051: new Integer(0) }),
052: new STOwnCollectionT(new Object[] { new Integer(1),
053: new Integer(17),
054: new Integer(Integer.MAX_VALUE - 1) }),
055: new STOwnCollectionT(new Object[] { new Integer(3),
056: new Integer(17), new Integer(25),
057: new Integer(Integer.MAX_VALUE - 2) }),
058: new STOwnCollectionT(new Object[] { "foo",
059: new STElement("bar", "barbar") }),
060: new STOwnCollectionT(new Object[] { "foo2",
061: new STElement("bar", "barbar2") }) };
062: }
063:
064: public void testDefaultContainsInteger() {
065: Query q = st.query();
066: Object[] r = store();
067: q.constrain(new STOwnCollectionT(
068: new Object[] { new Integer(17) }));
069: st.expect(q, new Object[] { r[3], r[4] });
070: }
071:
072: public void testDefaultContainsString() {
073: Query q = st.query();
074: Object[] r = store();
075: q.constrain(new STOwnCollectionT(new Object[] { "foo" }));
076: st.expect(q, new Object[] { r[5] });
077: }
078:
079: public void testDefaultContainsTwo() {
080: Query q = st.query();
081: Object[] r = store();
082: q.constrain(new STOwnCollectionT(new Object[] {
083: new Integer(17), new Integer(25) }));
084: st.expect(q, new Object[] { r[4] });
085: }
086:
087: public void testDescendOne() {
088: Query q = st.query();
089: Object[] r = store();
090: q.constrain(STOwnCollectionT.class);
091: q.descend("col").constrain(new Integer(17));
092: st.expect(q, new Object[] { r[3], r[4] });
093: }
094:
095: public void testDescendTwo() {
096: Query q = st.query();
097: Object[] r = store();
098: q.constrain(STOwnCollectionT.class);
099: Query qElements = q.descend("col");
100: qElements.constrain(new Integer(17));
101: qElements.constrain(new Integer(25));
102: st.expect(q, new Object[] { r[4] });
103: }
104:
105: public void testDescendSmaller() {
106: Query q = st.query();
107: Object[] r = store();
108: q.constrain(STOwnCollectionT.class);
109: Query qElements = q.descend("col");
110: qElements.constrain(new Integer(3)).smaller();
111: st.expect(q, new Object[] { r[2], r[3] });
112: }
113:
114: public void testDefaultContainsObject() {
115: Query q = st.query();
116: Object[] r = store();
117: q.constrain(new STOwnCollectionT(new Object[] { new STElement(
118: "bar", null) }));
119: st.expect(q, new Object[] { r[5], r[6] });
120: }
121:
122: public void testDescendToObject() {
123: Query q = st.query();
124: Object[] r = store();
125: q.constrain(new STOwnCollectionT());
126: q.descend("col").descend("foo1").constrain("bar");
127: st.expect(q, new Object[] { r[5], r[6] });
128: }
129:
130: public static class MyCollection implements Collection {
131:
132: ArrayList myList;
133:
134: public MyCollection() {
135: myList = new ArrayList();
136: }
137:
138: public int size() {
139: return myList.size();
140: }
141:
142: public boolean isEmpty() {
143: return myList.isEmpty();
144: }
145:
146: public boolean contains(Object o) {
147: return myList.contains(o);
148: }
149:
150: public Iterator iterator() {
151: return myList.iterator();
152: }
153:
154: public Object[] toArray() {
155: return myList.toArray();
156: }
157:
158: public Object[] toArray(Object[] a) {
159: return myList.toArray(a);
160: }
161:
162: public boolean add(Object o) {
163: return myList.add(o);
164: }
165:
166: public boolean remove(Object o) {
167: return myList.remove(o);
168: }
169:
170: public boolean containsAll(Collection c) {
171: return myList.containsAll(c);
172: }
173:
174: public boolean addAll(Collection c) {
175: return myList.addAll(c);
176: }
177:
178: public boolean removeAll(Collection c) {
179: return myList.removeAll(c);
180: }
181:
182: public boolean retainAll(Collection c) {
183: return myList.retainAll(c);
184: }
185:
186: public void clear() {
187: myList.clear();
188: }
189:
190: public boolean equals(Object o) {
191: return myList.equals(o);
192: }
193:
194: public int hashCode() {
195: return myList.hashCode();
196: }
197: }
198: }
|