private static Map < String , Object > guessPropertiesTypes ( Map < Object , Object > srcProperties ) { Map < String , Object > res = new HashMap <> ( ) ; for ( Map . Entry < Object , Object > prop : srcProperties . entrySet ( ) ) { Object value = prop . getValue ( ) ; if ( null != value && value instanceof String && ! Strings . isNullOrEmpty ( value . toString ( ) ) ) { try { value = Long . parseLong ( value . toString ( ) ) ; } catch ( NumberFormatException e ) { try { value = Double . parseDouble ( value . toString ( ) ) ; } catch ( NumberFormatException e2 ) { if ( value . toString ( ) . equalsIgnoreCase ( "true" ) || value . toString ( ) . equalsIgnoreCase ( "yes" ) ) { value = Boolean . TRUE ; } else if ( value . toString ( ) . equalsIgnoreCase ( "false" ) || value . toString ( ) . equalsIgnoreCase ( "no" ) ) { value = Boolean . FALSE ; } else { // nothing to do } } } } res . put ( prop . getKey ( ) . toString ( ) , value ) ; } return res ; }
Attempts to guess type types of a Properties . By default typesafe will make all property values Strings . This implementation will try to recognize booleans and numbers . All keys are treated as strings .