protected MessageFormat getMessageFormat ( ResourceBundle bundle , String code , Locale locale ) throws MissingResourceException { Map < String , Map < Locale , MessageFormat > > codeMap = this . cachedBundleMessageFormats . get ( bundle ) ; Map < Locale , MessageFormat > localeMap = null ; if ( codeMap != null ) { localeMap = codeMap . get ( code ) ; if ( localeMap != null ) { MessageFormat result = localeMap . get ( locale ) ; if ( result != null ) { return result ; } } } String msg = getStringOrNull ( bundle , code ) ; if ( msg != null ) { if ( codeMap == null ) { codeMap = new ConcurrentHashMap <> ( ) ; Map < String , Map < Locale , MessageFormat > > existing = this . cachedBundleMessageFormats . putIfAbsent ( bundle , codeMap ) ; if ( existing != null ) { codeMap = existing ; } } if ( localeMap == null ) { localeMap = new ConcurrentHashMap <> ( ) ; Map < Locale , MessageFormat > existing = codeMap . putIfAbsent ( code , localeMap ) ; if ( existing != null ) { localeMap = existing ; } } MessageFormat result = createMessageFormat ( msg , locale ) ; localeMap . put ( locale , result ) ; return result ; } return null ; }
Return a MessageFormat for the given bundle and code fetching already generated MessageFormats from the cache .