KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > legacy > soda > collections > STOwnCollectionW


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.test.legacy.soda.collections;
22
23 import java.util.*;
24
25 import com.db4o.query.*;
26 import com.db4o.test.legacy.soda.*;
27 import com.db4o.test.legacy.soda.collections.*;
28 import com.db4o.test.lib.*;
29
30 public class STOwnCollectionW implements STClass {
31
32     public static transient SodaTest st;
33     
34     Collection col;
35
36     public STOwnCollectionW() {
37
38     }
39
40     public STOwnCollectionW(Object JavaDoc[] arr) {
41         col = new MyCollection();
42         for (int i = 0; i < arr.length; i++) {
43             col.add(arr[i]);
44         }
45     }
46
47     public Object JavaDoc[] store() {
48         return new Object JavaDoc[] {
49             new STOwnCollectionW(),
50             new STOwnCollectionW(new Object JavaDoc[0]),
51             new STOwnCollectionW(new Object JavaDoc[] { new Integer JavaDoc(0), new Integer JavaDoc(0)}),
52             new STOwnCollectionW(
53                 new Object JavaDoc[] {
54                     new Integer JavaDoc(1),
55                     new Integer JavaDoc(17),
56                     new Integer JavaDoc(Integer.MAX_VALUE - 1)}),
57             new STOwnCollectionW(
58                 new Object JavaDoc[] {
59                     new Integer JavaDoc(3),
60                     new Integer JavaDoc(17),
61                     new Integer JavaDoc(25),
62                     new Integer JavaDoc(Integer.MAX_VALUE - 2)}),
63             new STOwnCollectionW(new Object JavaDoc[] { "foo", new STElement("bar", "barbar")}),
64             new STOwnCollectionW(new Object JavaDoc[] { "foo2", new STElement("bar", "barbar2")})
65         };
66     }
67     
68     public void testDefaultContainsInteger() {
69         Query q = st.query();
70         Object JavaDoc[] r = store();
71         q.constrain(new STOwnCollectionW(new Object JavaDoc[] { new Integer JavaDoc(17)}));
72         st.expect(q, new Object JavaDoc[] { r[3], r[4]});
73     }
74
75     public void testDefaultContainsString() {
76         Query q = st.query();
77         Object JavaDoc[] r = store();
78         q.constrain(new STOwnCollectionW(new Object JavaDoc[] { "foo" }));
79         st.expect(q, new Object JavaDoc[] { r[5] });
80     }
81
82     public void testDefaultContainsTwo() {
83         Query q = st.query();
84         Object JavaDoc[] r = store();
85         q.constrain(new STOwnCollectionW(new Object JavaDoc[] { new Integer JavaDoc(17), new Integer JavaDoc(25)}));
86         st.expect(q, new Object JavaDoc[] { r[4] });
87     }
88
89     public void testDescendOne() {
90         Query q = st.query();
91         Object JavaDoc[] r = store();
92         q.constrain(STOwnCollectionW.class);
93         q.descend("col").constrain(new Integer JavaDoc(17));
94         st.expect(q, new Object JavaDoc[] { r[3], r[4] });
95     }
96
97     public void testDescendTwo() {
98         Query q = st.query();
99         Object JavaDoc[] r = store();
100         q.constrain(STOwnCollectionW.class);
101         Query qElements = q.descend("col");
102         qElements.constrain(new Integer JavaDoc(17));
103         qElements.constrain(new Integer JavaDoc(25));
104         st.expect(q, new Object JavaDoc[] { r[4] });
105     }
106
107     public void testDescendSmaller() {
108         Query q = st.query();
109         Object JavaDoc[] r = store();
110         q.constrain(STOwnCollectionW.class);
111         Query qElements = q.descend("col");
112         qElements.constrain(new Integer JavaDoc(3)).smaller();
113         st.expect(q, new Object JavaDoc[] { r[2], r[3] });
114     }
115
116     public void testDefaultContainsObject() {
117         Query q = st.query();
118         Object JavaDoc[] r = store();
119         q.constrain(new STOwnCollectionW(new Object JavaDoc[] { new STElement("bar", null)}));
120         st.expect(q, new Object JavaDoc[] { r[5], r[6] });
121     }
122
123     public void testDescendToObject() {
124         Query q = st.query();
125         Object JavaDoc[] r = store();
126         q.constrain(new STOwnCollectionW());
127         q.descend("col").descend("foo1").constrain("bar");
128         st.expect(q, new Object JavaDoc[] { r[5], r[6] });
129     }
130
131     public static class MyCollection implements Collection {
132         
133         ArrayList myList;
134         
135         public MyCollection(){
136             myList = new ArrayList();
137         }
138         
139         public int size() {
140             return myList.size();
141         }
142
143         public boolean isEmpty() {
144             return myList.isEmpty();
145         }
146
147         public boolean contains(Object JavaDoc o) {
148             return myList.contains(o);
149         }
150
151         public Iterator iterator() {
152             return myList.iterator();
153         }
154
155         public Object JavaDoc[] toArray() {
156             return myList.toArray();
157         }
158
159         public Object JavaDoc[] toArray(Object JavaDoc[] a) {
160             return myList.toArray(a);
161         }
162
163         public boolean add(Object JavaDoc o) {
164             return myList.add(o);
165         }
166
167         public boolean remove(Object JavaDoc o) {
168             return myList.remove(o);
169         }
170
171         public boolean containsAll(Collection c) {
172             return myList.containsAll(c);
173         }
174
175         public boolean addAll(Collection c) {
176             return myList.addAll(c);
177         }
178
179         public boolean removeAll(Collection c) {
180             return myList.removeAll(c);
181         }
182
183         public boolean retainAll(Collection c) {
184             return myList.retainAll(c);
185         }
186
187         public void clear() {
188             myList.clear();
189         }
190
191         public boolean equals(Object JavaDoc o) {
192             if(o instanceof MyCollection){
193                 return new TCompare().isEqual(myList, ((MyCollection)o).myList);
194             }
195             return false;
196         }
197
198         public int hashCode() {
199             return myList.hashCode();
200         }
201     }
202 }
203
Popular Tags