src/java.base/share/classes/sun/util/locale/provider/CollatorProviderImpl.java

Print this page
rev 10528 : 8038436: Re-examine the mechanism to determine available localedata and cldrdata
Reviewed-by:

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -52,15 +52,14 @@
  * {@link java.text.spi.CollatorProvider CollatorProvider} class
  * for the JRE LocaleProviderAdapter.
  */
 public class CollatorProviderImpl extends CollatorProvider implements AvailableLanguageTags {
     private final LocaleProviderAdapter.Type type;
-    private final Set<String> langtags;
+    private Set<String> langtags;
 
-    public CollatorProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) {
+    public CollatorProviderImpl(LocaleProviderAdapter.Type type) {
         this.type = type;
-        this.langtags = langtags;
     }
 
     /**
      * Returns an array of all locales for which this locale service provider
      * can provide localized objects or names.

@@ -68,16 +67,16 @@
      * @return An array of all locales for which this locale service provider
      * can provide localized objects or names.
      */
     @Override
     public Locale[] getAvailableLocales() {
-        return LocaleProviderAdapter.toLocaleArray(langtags);
+        return LocaleProviderAdapter.toLocaleArray(getLangTags());
     }
 
     @Override
     public boolean isSupportedLocale(Locale locale) {
-        return LocaleProviderAdapter.isSupportedLocale(locale, type, langtags);
+        return LocaleProviderAdapter.isSupportedLocale(locale, type, getLangTags());
     }
 
     /**
      * Returns a new <code>Collator</code> instance for the specified locale.
      * @param locale the desired locale.

@@ -124,8 +123,15 @@
         return (Collator)result.clone();
     }
 
     @Override
     public Set<String> getAvailableLanguageTags() {
+        return getLangTags();
+    }
+
+    private Set<String> getLangTags() {
+        if (langtags == null) {
+            langtags = ((JRELocaleProviderAdapter)LocaleProviderAdapter.forType(type)).getLanguageTagSet("CollationData");
+        }
         return langtags;
     }
 }