diff options
| author | Benjamin Culkin <scorpress@gmail.com> | 2024-05-20 17:58:16 -0400 |
|---|---|---|
| committer | Benjamin Culkin <scorpress@gmail.com> | 2024-05-20 17:58:16 -0400 |
| commit | 40a9d99496e098562f090fb7ffce9e749011b131 (patch) | |
| tree | 437df24d65470582e943e494a52db8ed65a881ae /projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestMap.java | |
| parent | ff072dfe782f6f22123cd4ba050828d35c0d0fbd (diff) | |
Formatting pass
Diffstat (limited to 'projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestMap.java')
| -rw-r--r-- | projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestMap.java | 238 |
1 files changed, 108 insertions, 130 deletions
diff --git a/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestMap.java b/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestMap.java index 8a88e68..a7f4e06 100644 --- a/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestMap.java +++ b/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestMap.java @@ -12,153 +12,131 @@ import net.wotonomy.datastore.SerializedFileSoup; import net.wotonomy.datastore.XMLFileSoup; import net.wotonomy.foundation.internal.ValueConverter; -public class TestMap extends HashMap -{ - public TestMap() - { - put( "date", new Date() ); - put( "firstName", randomParse( - "Bert|Ernie|Elmo|Zoe|Arthur|Emily|DJ|Grover|Oscar|Max|Big|Twinkle") ); - put( "middleName", new StringBuffer( randomParse( - "Rufus|Remy|Martin|Josephus|Ulysses|Homer|Bart|Tip|Onegin|Meredith|Jay") ) ); - put( "lastName", randomParse( - "Alejandro|Alexander|Bird|Gosling|Joy|Van Hoff|Pedia|Marr|McNealy|Ping") ); - put( "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" ) ); - put( "city", randomParse( - "Springfield|Sterling|Cascades|Vienna|Reston|Paris|London|Runnymeade") ); - put( "state", randomParse( - "TX|NJ|NY|VA|DC|MD|NC|SC|WV|AR|FL|CA|TN" ) ); - put( "zip", ValueConverter.getInteger( - randomParse( "1|2|3|4" ) + "0" + randomParse( "0|1|2|3|5" ) + - randomParse( "6|7|8|9" ) + randomParse( "6|7|8|9" ) ) ); - put( "age", new Short( (short) ( new Random().nextDouble() * 40 + 18 ) ) ); +public class TestMap extends HashMap { + public TestMap() { + put("date", new Date()); + put("firstName", randomParse("Bert|Ernie|Elmo|Zoe|Arthur|Emily|DJ|Grover|Oscar|Max|Big|Twinkle")); + put("middleName", + new StringBuffer(randomParse("Rufus|Remy|Martin|Josephus|Ulysses|Homer|Bart|Tip|Onegin|Meredith|Jay"))); + put("lastName", randomParse("Alejandro|Alexander|Bird|Gosling|Joy|Van Hoff|Pedia|Marr|McNealy|Ping")); + put("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")); + put("city", randomParse("Springfield|Sterling|Cascades|Vienna|Reston|Paris|London|Runnymeade")); + put("state", randomParse("TX|NJ|NY|VA|DC|MD|NC|SC|WV|AR|FL|CA|TN")); + put("zip", ValueConverter.getInteger(randomParse("1|2|3|4") + "0" + randomParse("0|1|2|3|5") + + randomParse("6|7|8|9") + randomParse("6|7|8|9"))); + put("age", new Short((short) (new Random().nextDouble() * 40 + 18))); childCount = -1; - } - + } + protected int childCount; - public int getChildCount() - { - if ( childCount == -1 ) - { - //childCount = (int) ( random.nextDouble() * 6 ) - 3; // + 100; // tree scalability test - if ( childCount < 0 ) childCount = 0; + + public int getChildCount() { + if (childCount == -1) { + // childCount = (int) ( random.nextDouble() * 6 ) - 3; // + 100; // tree + // scalability test + if (childCount < 0) + childCount = 0; } - return childCount; + return childCount; }; - + protected TestMap[] children; - public TestMap[] getChildren() - { - if ( get( "children" ) == null ) - { + + public TestMap[] getChildren() { + if (get("children") == null) { int n = getChildCount(); - TestMap[] children = new TestMap[ n ]; - for ( int i = 0; i < n; i++ ) - { + TestMap[] children = new TestMap[n]; + for (int i = 0; i < n; i++) { children[i] = new TestMap(); } - put( "children", children ); + put("children", children); } - return (TestMap[]) get( "children" ); + return (TestMap[]) get("children"); } - public void setChildren( TestMap[] aChildArray ) - { - put( "children", aChildArray ); + + public void setChildren(TestMap[] aChildArray) { + put("children", aChildArray); } - public List getChildList() - { + + public List getChildList() { List result = new LinkedList(); TestMap[] childArray = getChildren(); - for ( int i = 0; i < childArray.length; i++ ) - { - result.add( childArray[i] ); + for (int i = 0; i < childArray.length; i++) { + result.add(childArray[i]); } return result; } - public void setChildList( List aChildList ) - { - TestMap[] children = new TestMap[ aChildList.size() ]; - for ( int i = 0; i < children.length; i++ ) - { - children[i] = (TestMap) aChildList.get( i ); + + public void setChildList(List aChildList) { + TestMap[] children = new TestMap[aChildList.size()]; + for (int i = 0; i < children.length; i++) { + children[i] = (TestMap) aChildList.get(i); } - setChildren( children ); + setChildren(children); } - - public String getFullName() - { - return get( "firstName" ) + " " + get( "middleName" ) + " " + get( "lastName" ); - } - - public boolean equals( Object anObject ) - { - return anObject == this; - } - - public String toString() - { - return "[" + getClass().getName() + ":" + getFullName() + "]"; + + public String getFullName() { + return get("firstName") + " " + get("middleName") + " " + get("lastName"); + } + + public boolean equals(Object anObject) { + return anObject == this; + } + + public String toString() { + return "[" + getClass().getName() + ":" + 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; + } + + 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("testMaps-xml"); + } else { + store = new SerializedFileSoup("testMaps-java"); + } + + Object o; + for (int i = 0; i < count; i++) { + store.addObject(new TestMap()); + } + /* + * store.addIndex( "age", "age" ); store.addIndex( "zipCode", "zipCode" ); + * store.addIndex( "firstName", "firstName" ); store.addIndex( "lastName", + * "lastName" ); + */ + System.out.println(System.currentTimeMillis() - millis + " milliseconds"); } - - // 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; - } - - 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( "testMaps-xml" ); - } - else - { - store = new SerializedFileSoup( "testMaps-java" ); - } - - Object o; - for ( int i = 0; i < count; i++ ) - { - store.addObject( new TestMap() ); - } - /* - store.addIndex( "age", "age" ); - store.addIndex( "zipCode", "zipCode" ); - store.addIndex( "firstName", "firstName" ); - store.addIndex( "lastName", "lastName" ); -*/ -System.out.println( System.currentTimeMillis() - millis + " milliseconds" ); - } } |
