1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
package net.wotonomy.test;
import java.io.Serializable;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.StringTokenizer;
import net.wotonomy.control.EOEditingContext;
import net.wotonomy.control.EOKeyValueCodingSupport;
import net.wotonomy.datastore.DataSoup;
import net.wotonomy.datastore.SerializedFileSoup;
import net.wotonomy.datastore.XMLFileSoup;
import net.wotonomy.foundation.internal.ValueConverter;
public class TestObject implements Serializable // , EOKeyValueCoding
{
static final long serialVersionUID = -5482454640042392838L;
// for testing manual array faulting
public EOEditingContext editingContext;
public EOEditingContext getEditingContext() { return editingContext; };
public TestObject()
{
date = new Date();
firstName = randomParse(
"Bert|Ernie|Elmo|Zoe|Arthur|Emily|DJ|Grover|Oscar|Max|Big|Twinkle");
middleName = new StringBuffer( randomParse(
"Rufus|Remy|Martin|Josephus|Ulysses|Homer|Bart|Tip|Onegin|Meredith|Jay") );
lastName = randomParse(
"Alejandro|Alexander|Bird|Gosling|Joy|Van Hoff|Pedia|Marr|McNealy|Ping");
address = randomParse( "1|2|3|4" ) + randomParse( "0|1|00|10|5|50" ) +
randomParse( "0|00|1|01|5|05|9|09||000" ) + " " + randomParse(
"Merry|Berry|Perry|Jerry|Meadow|Falls|Elm|Raspberry|Strawberry") + " "
+ randomParse( "Road|Lane|Court|Drive|Parkway|Terrace" );
city = randomParse(
"Springfield|Sterling|Cascades|Vienna|Reston|Paris|London|Runnymeade");
state = randomParse(
"TX|NJ|NY|VA|DC|MD|NC|SC|WV|AR|FL|CA|TN" );
zip = ValueConverter.getIntValue(
randomParse( "1|2|3|4" ) + "0" + randomParse( "0|1|2|3|5" ) +
randomParse( "6|7|8|9" ) + randomParse( "6|7|8|9" ) );
age = (short) ( new Random().nextDouble() * 40 + 18 );
childCount = -1;
// children = null;
childList = null;
}
protected Date date;
public Date getCreateDate() { return date; }
public void setCreateDate( Date aDate ) { date = aDate; }
protected String firstName;
public String getFirstName() { return firstName; }
public void setFirstName( String aName ) { firstName = aName; }
protected String lastName;
public String getLastName() { return lastName; }
public void setLastName( String aName ) {
if ( "Jones".equals( aName ) ) throw new RuntimeException( "Jones not allowed" ) ;
lastName = aName;
}
protected StringBuffer middleName;
public StringBuffer getMiddleName() { return middleName; }
public void setMiddleName( StringBuffer aName ) { middleName = aName; }
protected String address;
public String getAddress() { return address; }
public void setAddress( String anAddress ) { address = anAddress; }
protected String city;
public String getCity() { return city; }
public void setCity( String aCity ) { city = aCity; }
protected String state;
public String getState() { return state; }
public void setState( String aState ) { state = aState; }
protected int zip;
public int getZipCode() { return zip; }
public void setZipCode( int aZipCode ) { zip = aZipCode; }
protected short age;
public short getAge() { return age; }
public void setAge( short anAge ) { age = anAge; }
protected boolean special;
public Boolean isSpecial() { return new Boolean( special ); }
public void setSpecial( Boolean isSpecial ) { special = isSpecial.booleanValue(); }
/*
protected Object[] children;
private Object[] getChildren()
{
if ( children == null )
{
int n = getChildCount();
children = new Object[ n ];
for ( int i = 0; i < n; i++ )
{
children[i] = new TestObject();
}
//System.out.println( "TestObject.getChildren: " + toString() + " : " + getChildCount() );
}
return children;
}
private void setChildren( Object[] aChildArray )
{
children = aChildArray;
childCount = aChildArray.length;
}
// following child list implementation wraps child array
public List getChildList()
{
List result = new LinkedList();
Object[] childArray = getChildren();
for ( int i = 0; i < childArray.length; i++ )
{
result.add( childArray[i] );
}
return result;
}
public void setChildList( List aChildList )
{
children = new Object[ aChildList.size() ];
for ( int i = 0; i < children.length; i++ )
{
children[i] = (TestObject) aChildList.get( i );
}
childCount = children.length;
}
*/
protected int childCount;
public int getChildCount()
{
if ( childCount == -1 )
{
// uncomment this to enable random children
// childCount = (int) ( random.nextDouble() * 6 ) - 3; // + 100; // tree scalability test
if ( childCount < 0 ) childCount = 0;
}
// this tests internal count
// return childCount;
// this tests deferred count
if ( childList != null )
{
return childList.size();
}
else
{
return 0;
}
};
// following child list implementation stands alone
protected List childList;
public List getChildList()
{
/*
// this tests random child population
if ( childList == null )
{
int n = getChildCount();
childList = new LinkedList();
for ( int i = 0; i < n; i++ )
{
childList.add( new TestObject() );
}
}
*/
// this tests manual loading
if ( childList == null )
{
childList = new LinkedList();
}
return childList;
}
public void setChildList( List aChildList )
{
childList = aChildList;
}
protected TestObject parent;
public TestObject getParent() { return parent; }
public void setParent( TestObject anObject ) { parent = anObject; }
public String getHash() { return Integer.toHexString( System.identityHashCode( this ) ); }
public String getFullName()
{
// return getHash() + ": " + firstName + " " + middleName + " " + lastName;
return firstName + " " + middleName + " " + lastName;
}
public boolean equals( Object anObject )
{
return anObject == this;
}
public String toString()
{
return "[" + getClass().getName()
+ "@" + Integer.toHexString( System.identityHashCode(this) )
+ ":" + getFullName() + "]";
}
// statics
private static Random random = new Random();
private static String randomParse( String aString )
{
String result = "";
StringTokenizer tokens = new StringTokenizer( aString, "|" );
int n = (int) ( random.nextDouble() * tokens.countTokens() );
for ( int i = 0; i <= n; i++ )
{
result = tokens.nextToken();
}
return result;
}
// interface EOKeyValueCoding:
// disable this interface by commenting out the "implements" declaration
/**
* Returns the value for the specified property.
* If the property does not exist, this method should
* call handleQueryWithUnboundKey.
*/
public Object valueForKey( String aKey )
{
System.out.println( "valueForKey: " + aKey );
return EOKeyValueCodingSupport.valueForKey( this, aKey );
}
/**
* Sets the property to the specified value.
* If the property does not exist, this method should
* call handleTakeValueForUnboundKey.
* If the property is of a type that cannot allow
* null (e.g. primitive types) and aValue is null,
* this method should call unableToSetNullForKey.
*/
public void takeValueForKey( Object aValue, String aKey )
{
System.out.println( "takeValueForKey: " + aValue + " : " + aKey );
EOKeyValueCodingSupport.takeValueForKey( this, aValue, aKey );
}
/**
* Returns the value for the private field that
* corresponds to the specified property.
*/
public Object storedValueForKey( String aKey )
{
System.out.println( "storedValueForKey: " + aKey );
return EOKeyValueCodingSupport.storedValueForKey( this, aKey );
}
/**
* Sets the the private field that corresponds to the
* specified property to the specified value.
*/
public void takeStoredValueForKey( Object aValue, String aKey )
{
System.out.println( "takeStoredValueForKey: " + aValue + " : " + aKey );
EOKeyValueCodingSupport.takeStoredValueForKey( this, aValue, aKey );
}
/**
* Called by valueForKey when the specified key is
* not found on this object. Implementing classes
* should handle the specified value or otherwise
* throw an exception.
*/
public Object handleQueryWithUnboundKey( String aKey )
{
System.out.println( "handleQueryWithUnboundKey: " + aKey );
return EOKeyValueCodingSupport.handleQueryWithUnboundKey( this, aKey );
}
/**
* Called by takeValueForKey when the specified key
* is not found on this object. Implementing classes
* should handle the specified value or otherwise
* throw an exception.
*/
public void handleTakeValueForUnboundKey( Object aValue, String aKey )
{
System.out.println( "handleTakeValueForUnboundKey: " + aValue + " : " + aKey );
EOKeyValueCodingSupport.handleTakeValueForUnboundKey( this, aValue, aKey );
}
/**
* Called by takeValueForKey when the type of the
* specified key is not allowed to be null, as is
* the case with primitive types. Implementing
* classes should handle this case appropriately
* or otherwise throw an exception.
*/
public void unableToSetNullForKey( String aKey )
{
System.out.println( "unableToSetNullForKey: " + aKey );
EOKeyValueCodingSupport.unableToSetNullForKey( this, aKey );
}
// main entry point
public static void main( String[] argv )
{
int count = 100;
boolean xmlMode = false;
if ( argv.length > 0 )
{
Integer parsed = ValueConverter.getInteger( argv[0] );
if ( parsed != null ) count = parsed.intValue();
if ( argv.length > 1 )
{
if ( argv[1].indexOf( "xml" ) > -1 )
{
xmlMode = true;
}
}
}
long millis = System.currentTimeMillis();
DataSoup store = null;
if ( xmlMode )
{
store = new XMLFileSoup( "testObjects-xml" );
}
else
{
store = new SerializedFileSoup( "testObjects-java" );
}
Object o;
for ( int i = 0; i < count; i++ )
{
store.addObject( new TestObject() );
}
/*
store.addIndex( "age", "age" );
store.addIndex( "zipCode", "zipCode" );
store.addIndex( "firstName", "firstName" );
store.addIndex( "lastName", "lastName" );
*/
System.out.println( System.currentTimeMillis() - millis + " milliseconds" );
}
}
|