< prev index next >

src/java.base/share/classes/sun/util/cldr/CLDRLocaleProviderAdapter.java

Print this page
rev 59021 : 8244152: Remove unnecessary hash map resize in LocaleProviderAdapters
Reviewed-by: joehw, vtewari
   1 /*
   2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 207         // in CLDR adapter.
 208         category = "AvailableLocales";
 209 
 210         // Directly call Base tags, as we know it's in the base module.
 211         String supportedLocaleString = baseMetaInfo.availableLanguageTags(category);
 212         String nonBaseTags = null;
 213 
 214         if (nonBaseMetaInfo != null) {
 215             nonBaseTags = nonBaseMetaInfo.availableLanguageTags(category);
 216         }
 217         if (nonBaseTags != null) {
 218             if (supportedLocaleString != null) {
 219                 supportedLocaleString += " " + nonBaseTags;
 220             } else {
 221                 supportedLocaleString = nonBaseTags;
 222             }
 223         }
 224         if (supportedLocaleString == null) {
 225             return Collections.emptySet();
 226         }
 227         Set<String> tagset = new HashSet<>();
 228         StringTokenizer tokens = new StringTokenizer(supportedLocaleString);

 229         while (tokens.hasMoreTokens()) {
 230             tagset.add(tokens.nextToken());
 231         }
 232         return tagset;
 233     }
 234 
 235     // Implementation of ResourceBundleBasedAdapter
 236     @Override
 237     public List<Locale> getCandidateLocales(String baseName, Locale locale) {
 238         List<Locale> candidates = super.getCandidateLocales(baseName, applyAliases(locale));
 239         return applyParentLocales(baseName, candidates);
 240     }
 241 
 242     private List<Locale> applyParentLocales(String baseName, List<Locale> candidates) {
 243         // check irregular parents
 244         for (int i = 0; i < candidates.size(); i++) {
 245             Locale l = candidates.get(i);
 246             if (!l.equals(Locale.ROOT)) {
 247                 Locale p = getParentLocale(l);
 248                 if (p != null &&


   1 /*
   2  * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 207         // in CLDR adapter.
 208         category = "AvailableLocales";
 209 
 210         // Directly call Base tags, as we know it's in the base module.
 211         String supportedLocaleString = baseMetaInfo.availableLanguageTags(category);
 212         String nonBaseTags = null;
 213 
 214         if (nonBaseMetaInfo != null) {
 215             nonBaseTags = nonBaseMetaInfo.availableLanguageTags(category);
 216         }
 217         if (nonBaseTags != null) {
 218             if (supportedLocaleString != null) {
 219                 supportedLocaleString += " " + nonBaseTags;
 220             } else {
 221                 supportedLocaleString = nonBaseTags;
 222             }
 223         }
 224         if (supportedLocaleString == null) {
 225             return Collections.emptySet();
 226         }

 227         StringTokenizer tokens = new StringTokenizer(supportedLocaleString);
 228         Set<String> tagset = new HashSet<>(Math.max((int)(tokens.countTokens() / 0.75f) + 1, 16));
 229         while (tokens.hasMoreTokens()) {
 230             tagset.add(tokens.nextToken());
 231         }
 232         return tagset;
 233     }
 234 
 235     // Implementation of ResourceBundleBasedAdapter
 236     @Override
 237     public List<Locale> getCandidateLocales(String baseName, Locale locale) {
 238         List<Locale> candidates = super.getCandidateLocales(baseName, applyAliases(locale));
 239         return applyParentLocales(baseName, candidates);
 240     }
 241 
 242     private List<Locale> applyParentLocales(String baseName, List<Locale> candidates) {
 243         // check irregular parents
 244         for (int i = 0; i < candidates.size(); i++) {
 245             Locale l = candidates.get(i);
 246             if (!l.equals(Locale.ROOT)) {
 247                 Locale p = getParentLocale(l);
 248                 if (p != null &&


< prev index next >