671 672 // Copy values of a cached instance if any. 673 SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale); 674 DateFormatSymbols dfs; 675 if (ref != null && (dfs = ref.get()) != null) { 676 copyMembers(dfs, this); 677 return; 678 } 679 680 // Initialize the fields from the ResourceBundle for locale. 681 LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); 682 // Avoid any potential recursions 683 switch (adapter.getAdapterType()) { 684 case HOST: 685 case SPI: 686 adapter = LocaleProviderAdapter.getResourceBundleBased(); 687 break; 688 } 689 ResourceBundle resource = adapter.getLocaleData().getDateFormatData(locale); 690 691 eras = resource.getStringArray("Eras"); 692 months = resource.getStringArray("MonthNames"); 693 shortMonths = resource.getStringArray("MonthAbbreviations"); 694 ampms = resource.getStringArray("AmPmMarkers"); 695 localPatternChars = resource.getString("DateTimePatternChars"); 696 697 // Day of week names are stored in a 1-based array. 698 weekdays = toOneBasedArray(resource.getStringArray("DayNames")); 699 shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations")); 700 701 // Put a clone in the cache 702 ref = new SoftReference<>((DateFormatSymbols)this.clone()); 703 SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref); 704 if (x != null) { 705 DateFormatSymbols y = x.get(); 706 if (y == null) { 707 // Replace the empty SoftReference with ref. 708 cachedInstances.put(locale, ref); 709 } 710 } 711 } | 671 672 // Copy values of a cached instance if any. 673 SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale); 674 DateFormatSymbols dfs; 675 if (ref != null && (dfs = ref.get()) != null) { 676 copyMembers(dfs, this); 677 return; 678 } 679 680 // Initialize the fields from the ResourceBundle for locale. 681 LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); 682 // Avoid any potential recursions 683 switch (adapter.getAdapterType()) { 684 case HOST: 685 case SPI: 686 adapter = LocaleProviderAdapter.getResourceBundleBased(); 687 break; 688 } 689 ResourceBundle resource = adapter.getLocaleData().getDateFormatData(locale); 690 691 // JRE and CLDR use different keys 692 // JRE: Eras, short.Eras and narrow.Eras 693 // CLDR: long.Eras, Eras and narrow.Eras 694 if (resource.containsKey("Eras")) { 695 eras = resource.getStringArray("Eras"); 696 } else if (resource.containsKey("long.Eras")) { 697 eras = resource.getStringArray("long.Eras"); 698 } else if (resource.containsKey("short.Eras")) { 699 eras = resource.getStringArray("short.Eras"); 700 } 701 months = resource.getStringArray("MonthNames"); 702 shortMonths = resource.getStringArray("MonthAbbreviations"); 703 ampms = resource.getStringArray("AmPmMarkers"); 704 localPatternChars = resource.getString("DateTimePatternChars"); 705 706 // Day of week names are stored in a 1-based array. 707 weekdays = toOneBasedArray(resource.getStringArray("DayNames")); 708 shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations")); 709 710 // Put a clone in the cache 711 ref = new SoftReference<>((DateFormatSymbols)this.clone()); 712 SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref); 713 if (x != null) { 714 DateFormatSymbols y = x.get(); 715 if (y == null) { 716 // Replace the empty SoftReference with ref. 717 cachedInstances.put(locale, ref); 718 } 719 } 720 } |