public String toPattern ( ) { // later, make this more extensible int lastOffset = 0 ; StringBuilder result = new StringBuilder ( ) ; for ( int i = 0 ; i <= maxOffset ; ++ i ) { copyAndFixQuotes ( pattern , lastOffset , offsets [ i ] , result ) ; lastOffset = offsets [ i ] ; result . append ( ' ' ) . append ( argumentNumbers [ i ] ) ; Format fmt = formats [ i ] ; if ( fmt == null ) { // do nothing, string format } else if ( fmt instanceof NumberFormat ) { if ( fmt . equals ( NumberFormat . getInstance ( locale ) ) ) { result . append ( ",number" ) ; } else if ( fmt . equals ( NumberFormat . getCurrencyInstance ( locale ) ) ) { result . append ( ",number,currency" ) ; } else if ( fmt . equals ( NumberFormat . getPercentInstance ( locale ) ) ) { result . append ( ",number,percent" ) ; } else if ( fmt . equals ( NumberFormat . getIntegerInstance ( locale ) ) ) { result . append ( ",number,integer" ) ; } else { if ( fmt instanceof DecimalFormat ) { result . append ( ",number," ) . append ( ( ( DecimalFormat ) fmt ) . toPattern ( ) ) ; } else if ( fmt instanceof ChoiceFormat ) { result . append ( ",choice," ) . append ( ( ( ChoiceFormat ) fmt ) . toPattern ( ) ) ; } else { // UNKNOWN } } } else if ( fmt instanceof DateFormat ) { int index ; for ( index = MODIFIER_DEFAULT ; index < DATE_TIME_MODIFIERS . length ; index ++ ) { DateFormat df = DateFormat . getDateInstance ( DATE_TIME_MODIFIERS [ index ] , locale ) ; if ( fmt . equals ( df ) ) { result . append ( ",date" ) ; break ; } df = DateFormat . getTimeInstance ( DATE_TIME_MODIFIERS [ index ] , locale ) ; if ( fmt . equals ( df ) ) { result . append ( ",time" ) ; break ; } } if ( index >= DATE_TIME_MODIFIERS . length ) { if ( fmt instanceof SimpleDateFormat ) { result . append ( ",date," ) . append ( ( ( SimpleDateFormat ) fmt ) . toPattern ( ) ) ; } else { // UNKNOWN } } else if ( index != MODIFIER_DEFAULT ) { result . append ( ' ' ) . append ( DATE_TIME_MODIFIER_KEYWORDS [ index ] ) ; } } else { //result.append(", unknown"); } result . append ( ' ' ) ; } copyAndFixQuotes ( pattern , lastOffset , pattern . length ( ) , result ) ; return result . toString ( ) ; }
Returns a pattern representing the current state of the message format . The string is constructed from internal information and therefore does not necessarily equal the previously applied pattern .