@ Override public final void applyPattern ( String pattern ) { if ( hasRegistry ( ) ) { super . applyPattern ( pattern ) ; toPattern = super . toPattern ( ) ; return ; } ArrayList < Format > foundFormats = new ArrayList < Format > ( ) ; ArrayList < String > foundDescriptions = new ArrayList < String > ( ) ; StringBuilder stripCustom = new StringBuilder ( pattern . length ( ) ) ; ParsePosition pos = new ParsePosition ( 0 ) ; char [ ] c = pattern . toCharArray ( ) ; int fmtCount = 0 ; while ( pos . getIndex ( ) < pattern . length ( ) ) { char charType = c [ pos . getIndex ( ) ] ; if ( QUOTE == charType ) { appendQuotedString ( pattern , pos , stripCustom , true ) ; continue ; } if ( START_FE == charType ) { fmtCount ++ ; seekNonWs ( pattern , pos ) ; int start = pos . getIndex ( ) ; int index = readArgumentIndex ( pattern , next ( pos ) ) ; stripCustom . append ( START_FE ) . append ( index ) ; seekNonWs ( pattern , pos ) ; Format format = null ; String formatDescription = null ; if ( c [ pos . getIndex ( ) ] == START_FMT ) { formatDescription = parseFormatDescription ( pattern , next ( pos ) ) ; format = getFormat ( formatDescription ) ; if ( format == null ) { stripCustom . append ( START_FMT ) . append ( formatDescription ) ; } } foundFormats . add ( format ) ; foundDescriptions . add ( format == null ? null : formatDescription ) ; Preconditions . checkState ( foundFormats . size ( ) == fmtCount ) ; Preconditions . checkState ( foundDescriptions . size ( ) == fmtCount ) ; if ( c [ pos . getIndex ( ) ] != END_FE ) { throw new IllegalArgumentException ( "Unreadable format element at position " + start ) ; } } //$FALL-THROUGH$ stripCustom . append ( c [ pos . getIndex ( ) ] ) ; next ( pos ) ; } super . applyPattern ( stripCustom . toString ( ) ) ; toPattern = insertFormats ( super . toPattern ( ) , foundDescriptions ) ; if ( containsElements ( foundFormats ) ) { Format [ ] origFormats = getFormats ( ) ; // only loop over what we know we have, as MessageFormat on Java 1.3 // seems to provide an extra format element: Iterator < Format > it = foundFormats . iterator ( ) ; for ( int i = 0 ; it . hasNext ( ) ; i ++ ) { Format f = it . next ( ) ; if ( f != null ) { origFormats [ i ] = f ; } } super . setFormats ( origFormats ) ; } }
Apply the specified pattern .