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