private static void setValue ( Postcard postcard , Integer typeDef , String key , String value ) { if ( TextUtils . isEmpty ( key ) || TextUtils . isEmpty ( value ) ) { return ; } try { if ( null != typeDef ) { if ( typeDef == TypeKind . BOOLEAN . ordinal ( ) ) { postcard . withBoolean ( key , Boolean . parseBoolean ( value ) ) ; } else if ( typeDef == TypeKind . BYTE . ordinal ( ) ) { postcard . withByte ( key , Byte . valueOf ( value ) ) ; } else if ( typeDef == TypeKind . SHORT . ordinal ( ) ) { postcard . withShort ( key , Short . valueOf ( value ) ) ; } else if ( typeDef == TypeKind . INT . ordinal ( ) ) { postcard . withInt ( key , Integer . valueOf ( value ) ) ; } else if ( typeDef == TypeKind . LONG . ordinal ( ) ) { postcard . withLong ( key , Long . valueOf ( value ) ) ; } else if ( typeDef == TypeKind . FLOAT . ordinal ( ) ) { postcard . withFloat ( key , Float . valueOf ( value ) ) ; } else if ( typeDef == TypeKind . DOUBLE . ordinal ( ) ) { postcard . withDouble ( key , Double . valueOf ( value ) ) ; } else if ( typeDef == TypeKind . STRING . ordinal ( ) ) { postcard . withString ( key , value ) ; } else if ( typeDef == TypeKind . PARCELABLE . ordinal ( ) ) { // TODO : How to description parcelable value with string? } else if ( typeDef == TypeKind . OBJECT . ordinal ( ) ) { postcard . withString ( key , value ) ; } else { // Compatible compiler sdk 1.0.3, in that version, the string type = 18 postcard . withString ( key , value ) ; } } else { postcard . withString ( key , value ) ; } } catch ( Throwable ex ) { logger . warning ( Consts . TAG , "LogisticsCenter setValue failed! " + ex . getMessage ( ) ) ; } }
Set value by known type