private void checkBuildRulesIdMaps ( ) { boolean haveMap ; synchronized ( this ) { haveMap = localeIdToCardinalRulesId != null ; } if ( ! haveMap ) { Map < String , String > tempLocaleIdToCardinalRulesId ; Map < String , String > tempLocaleIdToOrdinalRulesId ; Map < String , ULocale > tempRulesIdToEquivalentULocale ; try { UResourceBundle pluralb = getPluralBundle ( ) ; // Read cardinal-number rules. UResourceBundle localeb = pluralb . get ( "locales" ) ; // sort for convenience of getAvailableULocales tempLocaleIdToCardinalRulesId = new TreeMap < String , String > ( ) ; // not visible tempRulesIdToEquivalentULocale = new HashMap < String , ULocale > ( ) ; for ( int i = 0 ; i < localeb . getSize ( ) ; ++ i ) { UResourceBundle b = localeb . get ( i ) ; String id = b . getKey ( ) ; String value = b . getString ( ) . intern ( ) ; tempLocaleIdToCardinalRulesId . put ( id , value ) ; if ( ! tempRulesIdToEquivalentULocale . containsKey ( value ) ) { tempRulesIdToEquivalentULocale . put ( value , new ULocale ( id ) ) ; } } // Read ordinal-number rules. localeb = pluralb . get ( "locales_ordinals" ) ; tempLocaleIdToOrdinalRulesId = new TreeMap < String , String > ( ) ; for ( int i = 0 ; i < localeb . getSize ( ) ; ++ i ) { UResourceBundle b = localeb . get ( i ) ; String id = b . getKey ( ) ; String value = b . getString ( ) . intern ( ) ; tempLocaleIdToOrdinalRulesId . put ( id , value ) ; } } catch ( MissingResourceException e ) { // dummy so we don't try again tempLocaleIdToCardinalRulesId = Collections . emptyMap ( ) ; tempLocaleIdToOrdinalRulesId = Collections . emptyMap ( ) ; tempRulesIdToEquivalentULocale = Collections . emptyMap ( ) ; } synchronized ( this ) { if ( localeIdToCardinalRulesId == null ) { localeIdToCardinalRulesId = tempLocaleIdToCardinalRulesId ; localeIdToOrdinalRulesId = tempLocaleIdToOrdinalRulesId ; rulesIdToEquivalentULocale = tempRulesIdToEquivalentULocale ; } } } }
Lazily constructs the localeIdToRulesId and rulesIdToEquivalentULocale maps if necessary . These exactly reflect the contents of the locales resource in plurals . res .