Speed up compilation when locales are not used

This commit is contained in:
konsoletyper 2014-06-27 16:10:51 +04:00
parent b94d711732
commit 54e0c43fb2
2 changed files with 21 additions and 2 deletions

View File

@ -100,6 +100,7 @@
<argument>java.lang.reflect</argument> <argument>java.lang.reflect</argument>
<argument>java.io</argument> <argument>java.io</argument>
<argument>java.net</argument> <argument>java.net</argument>
<argument>java.text</argument>
<argument>java.util</argument> <argument>java.util</argument>
<argument>java.util.logging</argument> <argument>java.util.logging</argument>
<argument>java.util.concurrent</argument> <argument>java.util.concurrent</argument>

View File

@ -38,11 +38,22 @@ public class CLDRReader {
private Set<String> availableLocales = new LinkedHashSet<>(); private Set<String> availableLocales = new LinkedHashSet<>();
private Set<String> availableLanguages = new LinkedHashSet<>(); private Set<String> availableLanguages = new LinkedHashSet<>();
private Set<String> availableCountries = new LinkedHashSet<>(); private Set<String> availableCountries = new LinkedHashSet<>();
private boolean initialized;
private Properties properties;
private ClassLoader classLoader;
public CLDRReader(Properties properties, ClassLoader classLoader) { public CLDRReader(Properties properties, ClassLoader classLoader) {
this.properties = properties;
this.classLoader = classLoader;
}
private synchronized void ensureInitialized() {
if (!initialized) {
initialized = true;
findAvailableLocales(properties); findAvailableLocales(properties);
readCLDR(classLoader); readCLDR(classLoader);
} }
}
private void findAvailableLocales(Properties properties) { private void findAvailableLocales(Properties properties) {
String availableLocalesString = properties.getProperty("java.util.Locale.available", "en_EN").trim(); String availableLocalesString = properties.getProperty("java.util.Locale.available", "en_EN").trim();
@ -278,30 +289,37 @@ public class CLDRReader {
} }
public Map<String, CLDRLocale> getKnownLocales() { public Map<String, CLDRLocale> getKnownLocales() {
ensureInitialized();
return Collections.unmodifiableMap(knownLocales); return Collections.unmodifiableMap(knownLocales);
} }
public Set<String> getAvailableLocales() { public Set<String> getAvailableLocales() {
ensureInitialized();
return Collections.unmodifiableSet(availableLocales); return Collections.unmodifiableSet(availableLocales);
} }
public Set<String> getAvailableLanguages() { public Set<String> getAvailableLanguages() {
ensureInitialized();
return Collections.unmodifiableSet(availableLanguages); return Collections.unmodifiableSet(availableLanguages);
} }
public Set<String> getAvailableCountries() { public Set<String> getAvailableCountries() {
ensureInitialized();
return Collections.unmodifiableSet(availableCountries); return Collections.unmodifiableSet(availableCountries);
} }
public Map<String, Integer> getMinDaysMap() { public Map<String, Integer> getMinDaysMap() {
ensureInitialized();
return Collections.unmodifiableMap(minDaysMap); return Collections.unmodifiableMap(minDaysMap);
} }
public Map<String, Integer> getFirstDayMap() { public Map<String, Integer> getFirstDayMap() {
ensureInitialized();
return Collections.unmodifiableMap(firstDayMap); return Collections.unmodifiableMap(firstDayMap);
} }
public Map<String, String> getLikelySubtags() { public Map<String, String> getLikelySubtags() {
ensureInitialized();
return Collections.unmodifiableMap(likelySubtags); return Collections.unmodifiableMap(likelySubtags);
} }
} }