private void buildMap ( List < CLDR . Locale > availableBundles ) { // Index all bundles by their original bundle identifier and the maximum // bundle identifier. List < MetaLocale > maxBundleIds = new ArrayList <> ( ) ; for ( CLDR . Locale locale : availableBundles ) { MetaLocale source = ( MetaLocale ) locale ; if ( source . isRoot ( ) ) { continue ; } MetaLocale maxBundleId = languageResolver . addLikelySubtags ( source ) ; maxBundleIds . add ( maxBundleId ) ; availableBundlesMap . put ( source . copy ( ) , source ) ; if ( ! source . equals ( maxBundleId ) ) { availableBundlesMap . putIfAbsent ( maxBundleId . copy ( ) , source ) ; } } // Iterate over the maximum bundle identifiers, indexing the permutations // generated by our matching order. for ( MetaLocale bundleId : maxBundleIds ) { indexPermutations ( bundleId ) ; } }
Iterate over the available bundle identifiers expand them and index all permutations to enable a fast direct lookup .