24 */
25
26 package sun.util.locale.provider;
27
28 import java.lang.ref.SoftReference;
29 import java.text.*;
30 import java.text.spi.DateFormatProvider;
31 import java.text.spi.DateFormatSymbolsProvider;
32 import java.text.spi.DecimalFormatSymbolsProvider;
33 import java.text.spi.NumberFormatProvider;
34 import java.util.Collections;
35 import java.util.HashSet;
36 import java.util.Locale;
37 import java.util.Map;
38 import java.util.ResourceBundle.Control;
39 import java.util.Set;
40 import java.util.concurrent.ConcurrentHashMap;
41 import java.util.concurrent.ConcurrentMap;
42 import java.util.concurrent.atomic.AtomicReferenceArray;
43 import java.util.spi.CalendarDataProvider;
44 import java.util.spi.CurrencyNameProvider;
45 import java.util.spi.LocaleNameProvider;
46 import java.util.spi.TimeZoneNameProvider;
47
48 /**
49 * LocaleProviderAdapter implementation for the Mac OS X locale data
50 *
51 * @author Naoto Sato
52 */
53 public class HostLocaleProviderAdapterImpl {
54
55 // per supported locale instances
56 private static ConcurrentMap<Locale, SoftReference<AtomicReferenceArray<String>>> dateFormatPatternsMap =
57 new ConcurrentHashMap<>(2);
58 private static ConcurrentMap<Locale, SoftReference<AtomicReferenceArray<String>>> numberFormatPatternsMap =
59 new ConcurrentHashMap<>(2);
60 private static ConcurrentMap<Locale, SoftReference<DateFormatSymbols>> dateFormatSymbolsMap =
61 new ConcurrentHashMap<>(2);
62 private static ConcurrentMap<Locale, SoftReference<DecimalFormatSymbols>> decimalFormatSymbolsMap =
63 new ConcurrentHashMap<>(2);
307 decimalFormatSymbolsMap.put(locale, ref);
308 }
309 return (DecimalFormatSymbols)decimalFormatSymbols.clone();
310 }
311 };
312 }
313
314 public static CalendarDataProvider getCalendarDataProvider() {
315 return new CalendarDataProvider() {
316 @Override
317 public Locale[] getAvailableLocales() {
318 return getSupportedCalendarLocales();
319 }
320
321 @Override
322 public boolean isSupportedLocale(Locale locale) {
323 return isSupportedCalendarLocale(locale);
324 }
325
326 @Override
327 public String getDisplayName(String calType, int field, int value,
328 int style, Locale locale) {
329 return null;
330 }
331
332 @Override
333 public Map<String, Integer> getDisplayNames(String calType,
334 int field, int style, Locale locale) {
335 return null;
336 }
337
338 @Override
339 public int getFirstDayOfWeek(Locale locale) {
340 return getCalendarInt(locale.toLanguageTag(), CD_FIRSTDAYOFWEEK);
341 }
342
343 @Override
344 public int getMinimalDaysInFirstWeek(Locale locale) {
345 return getCalendarInt(locale.toLanguageTag(), CD_MINIMALDAYSINFIRSTWEEK);
346 }
347 };
348 }
349
350 public static CurrencyNameProvider getCurrencyNameProvider() {
351 return new CurrencyNameProvider() {
352 @Override
353 public Locale[] getAvailableLocales() {
354 return supportedLocale;
355 }
356
357 @Override
358 public boolean isSupportedLocale(Locale locale) {
359 // Ignore the extensions for now
360 return supportedLocaleSet.contains(locale.stripExtensions());
361 }
362
363 @Override
364 public String getDisplayName(String code, Locale locale) {
365 return getDisplayString(locale.toLanguageTag(), DN_CURRENCY_CODE, code);
|
24 */
25
26 package sun.util.locale.provider;
27
28 import java.lang.ref.SoftReference;
29 import java.text.*;
30 import java.text.spi.DateFormatProvider;
31 import java.text.spi.DateFormatSymbolsProvider;
32 import java.text.spi.DecimalFormatSymbolsProvider;
33 import java.text.spi.NumberFormatProvider;
34 import java.util.Collections;
35 import java.util.HashSet;
36 import java.util.Locale;
37 import java.util.Map;
38 import java.util.ResourceBundle.Control;
39 import java.util.Set;
40 import java.util.concurrent.ConcurrentHashMap;
41 import java.util.concurrent.ConcurrentMap;
42 import java.util.concurrent.atomic.AtomicReferenceArray;
43 import java.util.spi.CalendarDataProvider;
44 import java.util.spi.CalendarNameProvider;
45 import java.util.spi.CurrencyNameProvider;
46 import java.util.spi.LocaleNameProvider;
47 import java.util.spi.TimeZoneNameProvider;
48
49 /**
50 * LocaleProviderAdapter implementation for the Mac OS X locale data
51 *
52 * @author Naoto Sato
53 */
54 public class HostLocaleProviderAdapterImpl {
55
56 // per supported locale instances
57 private static ConcurrentMap<Locale, SoftReference<AtomicReferenceArray<String>>> dateFormatPatternsMap =
58 new ConcurrentHashMap<>(2);
59 private static ConcurrentMap<Locale, SoftReference<AtomicReferenceArray<String>>> numberFormatPatternsMap =
60 new ConcurrentHashMap<>(2);
61 private static ConcurrentMap<Locale, SoftReference<DateFormatSymbols>> dateFormatSymbolsMap =
62 new ConcurrentHashMap<>(2);
63 private static ConcurrentMap<Locale, SoftReference<DecimalFormatSymbols>> decimalFormatSymbolsMap =
64 new ConcurrentHashMap<>(2);
308 decimalFormatSymbolsMap.put(locale, ref);
309 }
310 return (DecimalFormatSymbols)decimalFormatSymbols.clone();
311 }
312 };
313 }
314
315 public static CalendarDataProvider getCalendarDataProvider() {
316 return new CalendarDataProvider() {
317 @Override
318 public Locale[] getAvailableLocales() {
319 return getSupportedCalendarLocales();
320 }
321
322 @Override
323 public boolean isSupportedLocale(Locale locale) {
324 return isSupportedCalendarLocale(locale);
325 }
326
327 @Override
328 public int getFirstDayOfWeek(Locale locale) {
329 return getCalendarInt(locale.toLanguageTag(), CD_FIRSTDAYOFWEEK);
330 }
331
332 @Override
333 public int getMinimalDaysInFirstWeek(Locale locale) {
334 return getCalendarInt(locale.toLanguageTag(), CD_MINIMALDAYSINFIRSTWEEK);
335 }
336 };
337 }
338
339 public static CalendarNameProvider getCalendarNameProvider() {
340 return new CalendarNameProvider() {
341 @Override
342 public Locale[] getAvailableLocales() {
343 return getSupportedCalendarLocales();
344 }
345
346 @Override
347 public boolean isSupportedLocale(Locale locale) {
348 return isSupportedCalendarLocale(locale);
349 }
350
351 @Override
352 public String getDisplayName(String calType, int field, int value,
353 int style, Locale locale) {
354 return null;
355 }
356
357 @Override
358 public Map<String, Integer> getDisplayNames(String calType,
359 int field, int style, Locale locale) {
360 return null;
361 }
362 };
363 }
364
365 public static CurrencyNameProvider getCurrencyNameProvider() {
366 return new CurrencyNameProvider() {
367 @Override
368 public Locale[] getAvailableLocales() {
369 return supportedLocale;
370 }
371
372 @Override
373 public boolean isSupportedLocale(Locale locale) {
374 // Ignore the extensions for now
375 return supportedLocaleSet.contains(locale.stripExtensions());
376 }
377
378 @Override
379 public String getDisplayName(String code, Locale locale) {
380 return getDisplayString(locale.toLanguageTag(), DN_CURRENCY_CODE, code);
|