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 29 public class STOwnCollectionT implements STClass { 30 31 public static transient SodaTest st; 32 33 MyCollection col; 34 35 public STOwnCollectionT() { 36 37 } 38 39 public STOwnCollectionT(Object [] arr) { 40 col = new MyCollection(); 41 for (int i = 0; i < arr.length; i++) { 42 col.add(arr[i]); 43 } 44 } 45 46 public Object [] store() { 47 return new Object [] { 48 new STOwnCollectionT(), 49 new STOwnCollectionT(new Object [0]), 50 new STOwnCollectionT(new Object [] { new Integer (0), new Integer (0)}), 51 new STOwnCollectionT( 52 new Object [] { 53 new Integer (1), 54 new Integer (17), 55 new Integer (Integer.MAX_VALUE - 1)}), 56 new STOwnCollectionT( 57 new Object [] { 58 new Integer (3), 59 new Integer (17), 60 new Integer (25), 61 new Integer (Integer.MAX_VALUE - 2)}), 62 new STOwnCollectionT(new Object [] { "foo", new STElement("bar", "barbar")}), 63 new STOwnCollectionT(new Object [] { "foo2", new STElement("bar", "barbar2")}) 64 }; 65 } 66 67 68 public void testDefaultContainsInteger() { 69 Query q = st.query(); 70 Object [] r = store(); 71 q.constrain(new STOwnCollectionT(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 STOwnCollectionT(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 STOwnCollectionT(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(STOwnCollectionT.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(STOwnCollectionT.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(STOwnCollectionT.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 STOwnCollectionT(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 STOwnCollectionT()); 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 return myList.equals(o); 193 } 194 195 public int hashCode() { 196 return myList.hashCode(); 197 } 198 } 199 } 200 | Popular Tags |