1 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 [] 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 [] store() { 48 return new Object [] { 49 new STOwnCollectionW(), 50 new STOwnCollectionW(new Object [0]), 51 new STOwnCollectionW(new Object [] { new Integer (0), new Integer (0)}), 52 new STOwnCollectionW( 53 new Object [] { 54 new Integer (1), 55 new Integer (17), 56 new Integer (Integer.MAX_VALUE - 1)}), 57 new STOwnCollectionW( 58 new Object [] { 59 new Integer (3), 60 new Integer (17), 61 new Integer (25), 62 new Integer (Integer.MAX_VALUE - 2)}), 63 new STOwnCollectionW(new Object [] { "foo", new STElement("bar", "barbar")}), 64 new STOwnCollectionW(new Object [] { "foo2", new STElement("bar", "barbar2")}) 65 }; 66 } 67 68 public void testDefaultContainsInteger() { 69 Query q = st.query(); 70 Object [] r = store(); 71 q.constrain(new STOwnCollectionW(new Object [] { new Integer (17)})); 72 st.expect(q, new Object [] { r[3], r[4]}); 73 } 74 75 public void testDefaultContainsString() { 76 Query q = st.query(); 77 Object [] r = store(); 78 q.constrain(new STOwnCollectionW(new Object [] { "foo" })); 79 st.expect(q, new Object [] { r[5] }); 80 } 81 82 public void testDefaultContainsTwo() { 83 Query q = st.query(); 84 Object [] r = store(); 85 q.constrain(new STOwnCollectionW(new Object [] { new Integer (17), new Integer (25)})); 86 st.expect(q, new Object [] { r[4] }); 87 } 88 89 public void testDescendOne() { 90 Query q = st.query(); 91 Object [] r = store(); 92 q.constrain(STOwnCollectionW.class); 93 q.descend("col").constrain(new Integer (17)); 94 st.expect(q, new Object [] { r[3], r[4] }); 95 } 96 97 public void testDescendTwo() { 98 Query q = st.query(); 99 Object [] r = store(); 100 q.constrain(STOwnCollectionW.class); 101 Query qElements = q.descend("col"); 102 qElements.constrain(new Integer (17)); 103 qElements.constrain(new Integer (25)); 104 st.expect(q, new Object [] { r[4] }); 105 } 106 107 public void testDescendSmaller() { 108 Query q = st.query(); 109 Object [] r = store(); 110 q.constrain(STOwnCollectionW.class); 111 Query qElements = q.descend("col"); 112 qElements.constrain(new Integer (3)).smaller(); 113 st.expect(q, new Object [] { r[2], r[3] }); 114 } 115 116 public void testDefaultContainsObject() { 117 Query q = st.query(); 118 Object [] r = store(); 119 q.constrain(new STOwnCollectionW(new Object [] { new STElement("bar", null)})); 120 st.expect(q, new Object [] { r[5], r[6] }); 121 } 122 123 public void testDescendToObject() { 124 Query q = st.query(); 125 Object [] r = store(); 126 q.constrain(new STOwnCollectionW()); 127 q.descend("col").descend("foo1").constrain("bar"); 128 st.expect(q, new Object [] { 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 o) { 148 return myList.contains(o); 149 } 150 151 public Iterator iterator() { 152 return myList.iterator(); 153 } 154 155 public Object [] toArray() { 156 return myList.toArray(); 157 } 158 159 public Object [] toArray(Object [] a) { 160 return myList.toArray(a); 161 } 162 163 public boolean add(Object o) { 164 return myList.add(o); 165 } 166 167 public boolean remove(Object 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 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 |