1 20 21 package com.methodhead.aikp; 22 23 import com.methodhead.persistable.Key; 24 import com.methodhead.persistable.Persistable; 25 import com.methodhead.persistable.PersistableException; 26 27 31 public class IntKey 32 implements 33 Key { 34 35 37 39 41 public IntKey() { 42 value_ = 0; 43 } 44 45 public IntKey( int i ) { 46 value_ = i; 47 } 48 49 public IntKey( Object o ) { 50 try { 51 value_ = Integer.parseInt( o.toString() ); 52 } 53 catch ( NumberFormatException e ) { 54 } 55 } 56 57 public IntKey( String s ) { 58 try { 59 value_ = Integer.parseInt( s ); 60 } 61 catch ( NumberFormatException e ) { 62 } 63 } 64 65 67 public boolean equals( Object o ) { 68 if ( o == null ) 69 return false; 70 71 if ( !getClass().isInstance( o ) ) 72 return false; 73 74 return value_ == ( ( IntKey )o ).value_; 75 } 76 77 public int hashCode() { 78 return value_; 79 } 80 81 public String toString() { 82 return String.valueOf( value_ ); 83 } 84 85 public String getWhereClause() { 86 return "id=" + value_; 87 } 88 89 public void setProperties( 90 Persistable persistable ) { 91 92 persistable.set( "id", new Integer ( value_ ) ); 93 } 94 95 public void setKeyValue( 96 Persistable persistable ) 97 throws 98 PersistableException { 99 100 value_ = ( ( Integer )persistable.get( "id" ) ).intValue(); 101 } 102 103 105 107 int value_; 108 } 109 110 111 112 113 | Popular Tags |