equal
deleted
inserted
replaced
502 private static final String GMT = "GMT"; |
502 private static final String GMT = "GMT"; |
503 |
503 |
504 /** |
504 /** |
505 * Cache to hold the DateTimePatterns of a Locale. |
505 * Cache to hold the DateTimePatterns of a Locale. |
506 */ |
506 */ |
507 private static final ConcurrentMap<String, String[]> cachedLocaleData |
507 private static final ConcurrentMap<Locale, String[]> cachedLocaleData |
508 = new ConcurrentHashMap<String, String[]>(3); |
508 = new ConcurrentHashMap<Locale, String[]>(3); |
509 |
509 |
510 /** |
510 /** |
511 * Cache NumberFormat instances with Locale key. |
511 * Cache NumberFormat instances with Locale key. |
512 */ |
512 */ |
513 private static final ConcurrentMap<Locale, NumberFormat> cachedNumberFormatData |
513 private static final ConcurrentMap<Locale, NumberFormat> cachedNumberFormatData |
617 this.locale = loc; |
617 this.locale = loc; |
618 // initialize calendar and related fields |
618 // initialize calendar and related fields |
619 initializeCalendar(loc); |
619 initializeCalendar(loc); |
620 |
620 |
621 /* try the cache first */ |
621 /* try the cache first */ |
622 String key = getKey(); |
622 String[] dateTimePatterns = cachedLocaleData.get(loc); |
623 String[] dateTimePatterns = cachedLocaleData.get(key); |
|
624 if (dateTimePatterns == null) { /* cache miss */ |
623 if (dateTimePatterns == null) { /* cache miss */ |
625 ResourceBundle r = LocaleData.getDateFormatData(loc); |
624 ResourceBundle r = LocaleData.getDateFormatData(loc); |
626 if (!isGregorianCalendar()) { |
625 if (!isGregorianCalendar()) { |
627 try { |
626 try { |
628 dateTimePatterns = r.getStringArray(getCalendarName() + ".DateTimePatterns"); |
627 dateTimePatterns = r.getStringArray(getCalendarName() + ".DateTimePatterns"); |
631 } |
630 } |
632 if (dateTimePatterns == null) { |
631 if (dateTimePatterns == null) { |
633 dateTimePatterns = r.getStringArray("DateTimePatterns"); |
632 dateTimePatterns = r.getStringArray("DateTimePatterns"); |
634 } |
633 } |
635 /* update cache */ |
634 /* update cache */ |
636 cachedLocaleData.putIfAbsent(key, dateTimePatterns); |
635 cachedLocaleData.putIfAbsent(loc, dateTimePatterns); |
637 } |
636 } |
638 formatData = DateFormatSymbols.getInstanceRef(loc); |
637 formatData = DateFormatSymbols.getInstanceRef(loc); |
639 if ((timeStyle >= 0) && (dateStyle >= 0)) { |
638 if ((timeStyle >= 0) && (dateStyle >= 0)) { |
640 Object[] dateTimeArgs = {dateTimePatterns[timeStyle], |
639 Object[] dateTimeArgs = {dateTimePatterns[timeStyle], |
641 dateTimePatterns[dateStyle + 4]}; |
640 dateTimePatterns[dateStyle + 4]}; |
680 // However, the calendar should use the current default TimeZone. |
679 // However, the calendar should use the current default TimeZone. |
681 // If this is not contained in the locale zone strings, then the zone |
680 // If this is not contained in the locale zone strings, then the zone |
682 // will be formatted using generic GMT+/-H:MM nomenclature. |
681 // will be formatted using generic GMT+/-H:MM nomenclature. |
683 calendar = Calendar.getInstance(TimeZone.getDefault(), loc); |
682 calendar = Calendar.getInstance(TimeZone.getDefault(), loc); |
684 } |
683 } |
685 } |
|
686 |
|
687 private String getKey() { |
|
688 StringBuilder sb = new StringBuilder(); |
|
689 sb.append(getCalendarName()).append('.'); |
|
690 sb.append(locale.getLanguage()).append('_').append(locale.getCountry()).append('_').append(locale.getVariant()); |
|
691 return sb.toString(); |
|
692 } |
684 } |
693 |
685 |
694 /** |
686 /** |
695 * Returns the compiled form of the given pattern. The syntax of |
687 * Returns the compiled form of the given pattern. The syntax of |
696 * the compiled pattern is: |
688 * the compiled pattern is: |