Coverage Report - net.wotonomy.test.TestMap
 
Classes in this File Line Coverage Branch Coverage Complexity
TestMap
0% 
0% 
2.182
 
 1  
 package net.wotonomy.test;
 2  
 
 3  
 import java.util.Date;
 4  
 import java.util.HashMap;
 5  
 import java.util.LinkedList;
 6  
 import java.util.List;
 7  
 import java.util.Random;
 8  
 import java.util.StringTokenizer;
 9  
 
 10  
 import net.wotonomy.datastore.DataSoup;
 11  
 import net.wotonomy.datastore.SerializedFileSoup;
 12  
 import net.wotonomy.datastore.XMLFileSoup;
 13  
 import net.wotonomy.foundation.internal.ValueConverter;
 14  
 
 15  0
 public class TestMap extends HashMap
 16  
 {
 17  0
     public TestMap()
 18  0
     {
 19  0
             put( "date", new Date() );
 20  0
             put( "firstName", randomParse(
 21  0
             "Bert|Ernie|Elmo|Zoe|Arthur|Emily|DJ|Grover|Oscar|Max|Big|Twinkle") );
 22  0
         put( "middleName", new StringBuffer( randomParse(
 23  0
             "Rufus|Remy|Martin|Josephus|Ulysses|Homer|Bart|Tip|Onegin|Meredith|Jay") ) );
 24  0
         put( "lastName", randomParse(
 25  0
             "Alejandro|Alexander|Bird|Gosling|Joy|Van Hoff|Pedia|Marr|McNealy|Ping") );
 26  0
         put( "address", randomParse( "1|2|3|4" ) + randomParse( "0|1|00|10|5|50" ) +
 27  0
             randomParse( "0|00|1|01|5|05|9|09||000" ) +        " " + randomParse(
 28  0
             "Merry|Berry|Perry|Jerry|Meadow|Falls|Elm|Raspberry|Strawberry") + " "
 29  0
             + randomParse( "Road|Lane|Court|Drive|Parkway|Terrace" ) );
 30  0
         put( "city", randomParse(
 31  0
             "Springfield|Sterling|Cascades|Vienna|Reston|Paris|London|Runnymeade") );
 32  0
         put( "state", randomParse(
 33  0
             "TX|NJ|NY|VA|DC|MD|NC|SC|WV|AR|FL|CA|TN" ) );
 34  0
         put( "zip", ValueConverter.getInteger(
 35  0
             randomParse( "1|2|3|4" ) + "0" + randomParse( "0|1|2|3|5" ) +
 36  0
             randomParse( "6|7|8|9" ) +        randomParse( "6|7|8|9" ) ) );
 37  0
         put( "age", new Short( (short) ( new Random().nextDouble() * 40 + 18 ) ) );
 38  0
                 childCount = -1;
 39  0
     }
 40  
     
 41  
         protected int childCount;
 42  
         public int getChildCount() 
 43  
         {
 44  0
                 if ( childCount == -1 )
 45  
                 {            
 46  
                         //childCount = (int) ( random.nextDouble() * 6 ) - 3; // + 100; // tree scalability test
 47  0
             if ( childCount < 0 ) childCount = 0;
 48  
                 }
 49  0
                 return childCount; 
 50  
         };
 51  
         
 52  
         protected TestMap[] children;
 53  
         public TestMap[] getChildren()
 54  
         {
 55  0
                 if ( get( "children" ) == null )
 56  
                 {
 57  0
                         int n = getChildCount();
 58  0
                         TestMap[] children = new TestMap[ n ];
 59  0
                         for ( int i = 0; i < n; i++ )
 60  
                         {
 61  0
                                 children[i] = new TestMap();
 62  
                         }
 63  0
             put( "children", children );
 64  
                 }
 65  0
                 return (TestMap[]) get( "children" );
 66  
         }
 67  
         public void setChildren( TestMap[] aChildArray )
 68  
         {
 69  0
                 put( "children", aChildArray );
 70  0
         }
 71  
         public List getChildList()
 72  
         {
 73  0
                 List result = new LinkedList();
 74  0
                 TestMap[] childArray = getChildren();
 75  0
                 for ( int i = 0; i < childArray.length; i++ )
 76  
                 {
 77  0
                         result.add( childArray[i] );        
 78  
                 }
 79  0
                 return result;
 80  
         }
 81  
         public void setChildList( List aChildList )
 82  
         {
 83  0
                 TestMap[] children = new TestMap[ aChildList.size() ];
 84  0
                 for ( int i = 0; i < children.length; i++ )
 85  
                 {
 86  0
                         children[i] = (TestMap) aChildList.get( i );        
 87  
                 }
 88  0
         setChildren( children );
 89  0
         }
 90  
     
 91  
     public String getFullName()
 92  
     {
 93  0
         return get( "firstName" ) + " " + get( "middleName" ) + " " + get( "lastName" );   
 94  
     }
 95  
     
 96  
     public boolean equals( Object anObject )
 97  
     {
 98  0
             return anObject == this;
 99  
     }
 100  
         
 101  
         public String toString()
 102  
         {
 103  0
                 return "[" + getClass().getName() + ":" + getFullName() + "]";        
 104  
         }
 105  
             
 106  
     // statics
 107  
     
 108  0
     private static Random random = new Random();
 109  
     private static String randomParse( String aString )
 110  
     {
 111  0
             String result = "";
 112  0
             StringTokenizer tokens = new StringTokenizer( aString, "|" );
 113  0
         int n = (int) ( random.nextDouble() * tokens.countTokens() );
 114  0
         for ( int i = 0; i <= n; i++ )
 115  
         {
 116  0
             result = tokens.nextToken();
 117  
         }
 118  0
         return result;
 119  
     }
 120  
     
 121  
     public static void main( String[] argv ) 
 122  
     {
 123  0
         int count = 100;
 124  0
         boolean xmlMode = false;
 125  0
         if ( argv.length > 0 )
 126  
         {
 127  0
             Integer parsed = ValueConverter.getInteger( argv[0] );
 128  0
             if ( parsed != null ) count = parsed.intValue();
 129  
             
 130  0
             if ( argv.length > 1 )
 131  
             {
 132  0
                 if ( argv[1].indexOf( "xml" ) > -1 )
 133  
                 {
 134  0
                     xmlMode = true;
 135  
                 }
 136  
             }
 137  
         }
 138  
 
 139  0
 long millis = System.currentTimeMillis();
 140  
         
 141  0
             DataSoup store = null;
 142  0
         if ( xmlMode )
 143  
         {
 144  0
             store = new XMLFileSoup( "testMaps-xml" );
 145  0
         }
 146  
         else
 147  
         {
 148  0
             store = new SerializedFileSoup( "testMaps-java" );
 149  
         }
 150  
                 
 151  
         Object o;
 152  0
         for ( int i = 0; i < count; i++ )
 153  
         {
 154  0
             store.addObject( new TestMap() );
 155  
         }
 156  
  /*
 157  
         store.addIndex( "age", "age" );
 158  
         store.addIndex( "zipCode", "zipCode" );
 159  
         store.addIndex( "firstName", "firstName" );
 160  
         store.addIndex( "lastName", "lastName" );
 161  
 */ 
 162  0
 System.out.println( System.currentTimeMillis() - millis + " milliseconds" );
 163  0
     }
 164  
 }