mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8208080: Locale extensions via Service provider is not working for region extensions
Reviewed-by: rriggs, nishjain
This commit is contained in:
parent
b2a6aa3e80
commit
4ab515f85c
5 changed files with 276 additions and 150 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -41,6 +41,7 @@ import java.util.spi.CalendarNameProvider;
|
||||||
public class CalendarDataUtility {
|
public class CalendarDataUtility {
|
||||||
public static final String FIRST_DAY_OF_WEEK = "firstDayOfWeek";
|
public static final String FIRST_DAY_OF_WEEK = "firstDayOfWeek";
|
||||||
public static final String MINIMAL_DAYS_IN_FIRST_WEEK = "minimalDaysInFirstWeek";
|
public static final String MINIMAL_DAYS_IN_FIRST_WEEK = "minimalDaysInFirstWeek";
|
||||||
|
private static final Locale.Builder OVERRIDE_BUILDER = new Locale.Builder();
|
||||||
|
|
||||||
// No instantiation
|
// No instantiation
|
||||||
private CalendarDataUtility() {
|
private CalendarDataUtility() {
|
||||||
|
@ -144,7 +145,9 @@ public class CalendarDataUtility {
|
||||||
rg.charAt(1) >= 0x0041 &&
|
rg.charAt(1) >= 0x0041 &&
|
||||||
rg.charAt(1) <= 0x005A &&
|
rg.charAt(1) <= 0x005A &&
|
||||||
rg.substring(2).equals("ZZZZ")) {
|
rg.substring(2).equals("ZZZZ")) {
|
||||||
override = new Locale.Builder().setLocale(l)
|
override = OVERRIDE_BUILDER
|
||||||
|
.clear()
|
||||||
|
.setLocale(l)
|
||||||
.setRegion(rg.substring(0, 2))
|
.setRegion(rg.substring(0, 2))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -40,6 +40,7 @@ import java.text.spi.DateFormatProvider;
|
||||||
import java.text.spi.DateFormatSymbolsProvider;
|
import java.text.spi.DateFormatSymbolsProvider;
|
||||||
import java.text.spi.DecimalFormatSymbolsProvider;
|
import java.text.spi.DecimalFormatSymbolsProvider;
|
||||||
import java.text.spi.NumberFormatProvider;
|
import java.text.spi.NumberFormatProvider;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
|
@ -110,17 +111,19 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
|
||||||
* Delegate interface. All the implementations have to have the class name
|
* Delegate interface. All the implementations have to have the class name
|
||||||
* following "<provider class name>Delegate" convention.
|
* following "<provider class name>Delegate" convention.
|
||||||
*/
|
*/
|
||||||
interface Delegate<P extends LocaleServiceProvider> {
|
private interface Delegate<P extends LocaleServiceProvider> {
|
||||||
public void addImpl(P impl);
|
default public void addImpl(P impl) {
|
||||||
public P getImpl(Locale locale);
|
for (Locale l : impl.getAvailableLocales()) {
|
||||||
|
getDelegateMap().putIfAbsent(l, impl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Obtain the real SPI implementation, using locale fallback
|
* Obtain the real SPI implementation, using locale fallback
|
||||||
*/
|
*/
|
||||||
private static <P extends LocaleServiceProvider> P getImpl(Map<Locale, P> map, Locale locale) {
|
default public P getImpl(Locale locale) {
|
||||||
for (Locale l : LocaleServiceProviderPool.getLookupLocales(locale)) {
|
for (Locale l : LocaleServiceProviderPool.getLookupLocales(locale.stripExtensions())) {
|
||||||
P ret = map.get(l);
|
P ret = getDelegateMap().get(l);
|
||||||
if (ret != null) {
|
if (ret != null) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -128,55 +131,80 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<Locale, P> getDelegateMap();
|
||||||
|
|
||||||
|
default public Locale[] getAvailableLocalesDelegate() {
|
||||||
|
return getDelegateMap().keySet().stream().toArray(Locale[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
default public boolean isSupportedLocaleDelegate(Locale locale) {
|
||||||
|
Map<Locale, P> map = getDelegateMap();
|
||||||
|
Locale override = CalendarDataUtility.findRegionOverride(locale);
|
||||||
|
|
||||||
|
// First, call the method with extensions (if any)
|
||||||
|
P impl = map.get(override);
|
||||||
|
if (impl != null) {
|
||||||
|
return impl.isSupportedLocale(override);
|
||||||
|
} else {
|
||||||
|
// The default behavior
|
||||||
|
Locale overrideNoExt = override.stripExtensions();
|
||||||
|
impl = map.get(overrideNoExt);
|
||||||
|
if (impl != null) {
|
||||||
|
return Arrays.stream(impl.getAvailableLocales())
|
||||||
|
.anyMatch(overrideNoExt::equals);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Delegates for the actual SPI implementations.
|
* Delegates for the actual SPI implementations.
|
||||||
*/
|
*/
|
||||||
static class BreakIteratorProviderDelegate extends BreakIteratorProvider
|
static class BreakIteratorProviderDelegate extends BreakIteratorProvider
|
||||||
implements Delegate<BreakIteratorProvider> {
|
implements Delegate<BreakIteratorProvider> {
|
||||||
private final ConcurrentMap<Locale, BreakIteratorProvider> map = new ConcurrentHashMap<>();
|
private final Map<Locale, BreakIteratorProvider> map = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addImpl(BreakIteratorProvider impl) {
|
public Map<Locale, BreakIteratorProvider> getDelegateMap() {
|
||||||
for (Locale l : impl.getAvailableLocales()) {
|
return map;
|
||||||
map.putIfAbsent(l, impl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BreakIteratorProvider getImpl(Locale locale) {
|
|
||||||
return SPILocaleProviderAdapter.getImpl(map, locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Locale[] getAvailableLocales() {
|
public Locale[] getAvailableLocales() {
|
||||||
return map.keySet().toArray(new Locale[0]);
|
return getAvailableLocalesDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupportedLocale(Locale locale) {
|
public boolean isSupportedLocale(Locale locale) {
|
||||||
return map.containsKey(locale);
|
return isSupportedLocaleDelegate(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BreakIterator getWordInstance(Locale locale) {
|
public BreakIterator getWordInstance(Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
BreakIteratorProvider bip = getImpl(locale);
|
BreakIteratorProvider bip = getImpl(locale);
|
||||||
return bip.getWordInstance(locale);
|
return bip.getWordInstance(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BreakIterator getLineInstance(Locale locale) {
|
public BreakIterator getLineInstance(Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
BreakIteratorProvider bip = getImpl(locale);
|
BreakIteratorProvider bip = getImpl(locale);
|
||||||
return bip.getLineInstance(locale);
|
return bip.getLineInstance(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BreakIterator getCharacterInstance(Locale locale) {
|
public BreakIterator getCharacterInstance(Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
BreakIteratorProvider bip = getImpl(locale);
|
BreakIteratorProvider bip = getImpl(locale);
|
||||||
return bip.getCharacterInstance(locale);
|
return bip.getCharacterInstance(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BreakIterator getSentenceInstance(Locale locale) {
|
public BreakIterator getSentenceInstance(Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
BreakIteratorProvider bip = getImpl(locale);
|
BreakIteratorProvider bip = getImpl(locale);
|
||||||
return bip.getSentenceInstance(locale);
|
return bip.getSentenceInstance(locale);
|
||||||
}
|
}
|
||||||
|
@ -184,32 +212,26 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
static class CollatorProviderDelegate extends CollatorProvider implements Delegate<CollatorProvider> {
|
static class CollatorProviderDelegate extends CollatorProvider implements Delegate<CollatorProvider> {
|
||||||
private final ConcurrentMap<Locale, CollatorProvider> map = new ConcurrentHashMap<>();
|
private final Map<Locale, CollatorProvider> map = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addImpl(CollatorProvider impl) {
|
public Map<Locale, CollatorProvider> getDelegateMap() {
|
||||||
for (Locale l : impl.getAvailableLocales()) {
|
return map;
|
||||||
map.putIfAbsent(l, impl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CollatorProvider getImpl(Locale locale) {
|
|
||||||
return SPILocaleProviderAdapter.getImpl(map, locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Locale[] getAvailableLocales() {
|
public Locale[] getAvailableLocales() {
|
||||||
return map.keySet().toArray(new Locale[0]);
|
return getAvailableLocalesDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupportedLocale(Locale locale) {
|
public boolean isSupportedLocale(Locale locale) {
|
||||||
return map.containsKey(locale);
|
return isSupportedLocaleDelegate(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collator getInstance(Locale locale) {
|
public Collator getInstance(Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
CollatorProvider cp = getImpl(locale);
|
CollatorProvider cp = getImpl(locale);
|
||||||
return cp.getInstance(locale);
|
return cp.getInstance(locale);
|
||||||
}
|
}
|
||||||
|
@ -217,44 +239,40 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
|
||||||
|
|
||||||
static class DateFormatProviderDelegate extends DateFormatProvider
|
static class DateFormatProviderDelegate extends DateFormatProvider
|
||||||
implements Delegate<DateFormatProvider> {
|
implements Delegate<DateFormatProvider> {
|
||||||
private final ConcurrentMap<Locale, DateFormatProvider> map = new ConcurrentHashMap<>();
|
private final Map<Locale, DateFormatProvider> map = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addImpl(DateFormatProvider impl) {
|
public Map<Locale, DateFormatProvider> getDelegateMap() {
|
||||||
for (Locale l : impl.getAvailableLocales()) {
|
return map;
|
||||||
map.putIfAbsent(l, impl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DateFormatProvider getImpl(Locale locale) {
|
|
||||||
return SPILocaleProviderAdapter.getImpl(map, locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Locale[] getAvailableLocales() {
|
public Locale[] getAvailableLocales() {
|
||||||
return map.keySet().toArray(new Locale[0]);
|
return getAvailableLocalesDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupportedLocale(Locale locale) {
|
public boolean isSupportedLocale(Locale locale) {
|
||||||
return map.containsKey(locale);
|
return isSupportedLocaleDelegate(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DateFormat getTimeInstance(int style, Locale locale) {
|
public DateFormat getTimeInstance(int style, Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
DateFormatProvider dfp = getImpl(locale);
|
DateFormatProvider dfp = getImpl(locale);
|
||||||
return dfp.getTimeInstance(style, locale);
|
return dfp.getTimeInstance(style, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DateFormat getDateInstance(int style, Locale locale) {
|
public DateFormat getDateInstance(int style, Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
DateFormatProvider dfp = getImpl(locale);
|
DateFormatProvider dfp = getImpl(locale);
|
||||||
return dfp.getDateInstance(style, locale);
|
return dfp.getDateInstance(style, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale locale) {
|
public DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
DateFormatProvider dfp = getImpl(locale);
|
DateFormatProvider dfp = getImpl(locale);
|
||||||
return dfp.getDateTimeInstance(dateStyle, timeStyle, locale);
|
return dfp.getDateTimeInstance(dateStyle, timeStyle, locale);
|
||||||
}
|
}
|
||||||
|
@ -262,32 +280,26 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
|
||||||
|
|
||||||
static class DateFormatSymbolsProviderDelegate extends DateFormatSymbolsProvider
|
static class DateFormatSymbolsProviderDelegate extends DateFormatSymbolsProvider
|
||||||
implements Delegate<DateFormatSymbolsProvider> {
|
implements Delegate<DateFormatSymbolsProvider> {
|
||||||
private final ConcurrentMap<Locale, DateFormatSymbolsProvider> map = new ConcurrentHashMap<>();
|
private final Map<Locale, DateFormatSymbolsProvider> map = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addImpl(DateFormatSymbolsProvider impl) {
|
public Map<Locale, DateFormatSymbolsProvider> getDelegateMap() {
|
||||||
for (Locale l : impl.getAvailableLocales()) {
|
return map;
|
||||||
map.putIfAbsent(l, impl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DateFormatSymbolsProvider getImpl(Locale locale) {
|
|
||||||
return SPILocaleProviderAdapter.getImpl(map, locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Locale[] getAvailableLocales() {
|
public Locale[] getAvailableLocales() {
|
||||||
return map.keySet().toArray(new Locale[0]);
|
return getAvailableLocalesDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupportedLocale(Locale locale) {
|
public boolean isSupportedLocale(Locale locale) {
|
||||||
return map.containsKey(locale);
|
return isSupportedLocaleDelegate(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DateFormatSymbols getInstance(Locale locale) {
|
public DateFormatSymbols getInstance(Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
DateFormatSymbolsProvider dfsp = getImpl(locale);
|
DateFormatSymbolsProvider dfsp = getImpl(locale);
|
||||||
return dfsp.getInstance(locale);
|
return dfsp.getInstance(locale);
|
||||||
}
|
}
|
||||||
|
@ -295,32 +307,26 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
|
||||||
|
|
||||||
static class DecimalFormatSymbolsProviderDelegate extends DecimalFormatSymbolsProvider
|
static class DecimalFormatSymbolsProviderDelegate extends DecimalFormatSymbolsProvider
|
||||||
implements Delegate<DecimalFormatSymbolsProvider> {
|
implements Delegate<DecimalFormatSymbolsProvider> {
|
||||||
private final ConcurrentMap<Locale, DecimalFormatSymbolsProvider> map = new ConcurrentHashMap<>();
|
private final Map<Locale, DecimalFormatSymbolsProvider> map = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addImpl(DecimalFormatSymbolsProvider impl) {
|
public Map<Locale, DecimalFormatSymbolsProvider> getDelegateMap() {
|
||||||
for (Locale l : impl.getAvailableLocales()) {
|
return map;
|
||||||
map.putIfAbsent(l, impl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DecimalFormatSymbolsProvider getImpl(Locale locale) {
|
|
||||||
return SPILocaleProviderAdapter.getImpl(map, locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Locale[] getAvailableLocales() {
|
public Locale[] getAvailableLocales() {
|
||||||
return map.keySet().toArray(new Locale[0]);
|
return getAvailableLocalesDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupportedLocale(Locale locale) {
|
public boolean isSupportedLocale(Locale locale) {
|
||||||
return map.containsKey(locale);
|
return isSupportedLocaleDelegate(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DecimalFormatSymbols getInstance(Locale locale) {
|
public DecimalFormatSymbols getInstance(Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
DecimalFormatSymbolsProvider dfsp = getImpl(locale);
|
DecimalFormatSymbolsProvider dfsp = getImpl(locale);
|
||||||
return dfsp.getInstance(locale);
|
return dfsp.getInstance(locale);
|
||||||
}
|
}
|
||||||
|
@ -328,50 +334,47 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
|
||||||
|
|
||||||
static class NumberFormatProviderDelegate extends NumberFormatProvider
|
static class NumberFormatProviderDelegate extends NumberFormatProvider
|
||||||
implements Delegate<NumberFormatProvider> {
|
implements Delegate<NumberFormatProvider> {
|
||||||
private final ConcurrentMap<Locale, NumberFormatProvider> map = new ConcurrentHashMap<>();
|
private final Map<Locale, NumberFormatProvider> map = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addImpl(NumberFormatProvider impl) {
|
public Map<Locale, NumberFormatProvider> getDelegateMap() {
|
||||||
for (Locale l : impl.getAvailableLocales()) {
|
return map;
|
||||||
map.putIfAbsent(l, impl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NumberFormatProvider getImpl(Locale locale) {
|
|
||||||
return SPILocaleProviderAdapter.getImpl(map, locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Locale[] getAvailableLocales() {
|
public Locale[] getAvailableLocales() {
|
||||||
return map.keySet().toArray(new Locale[0]);
|
return getAvailableLocalesDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupportedLocale(Locale locale) {
|
public boolean isSupportedLocale(Locale locale) {
|
||||||
return map.containsKey(locale);
|
return isSupportedLocaleDelegate(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NumberFormat getCurrencyInstance(Locale locale) {
|
public NumberFormat getCurrencyInstance(Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
NumberFormatProvider nfp = getImpl(locale);
|
NumberFormatProvider nfp = getImpl(locale);
|
||||||
return nfp.getCurrencyInstance(locale);
|
return nfp.getCurrencyInstance(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NumberFormat getIntegerInstance(Locale locale) {
|
public NumberFormat getIntegerInstance(Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
NumberFormatProvider nfp = getImpl(locale);
|
NumberFormatProvider nfp = getImpl(locale);
|
||||||
return nfp.getIntegerInstance(locale);
|
return nfp.getIntegerInstance(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NumberFormat getNumberInstance(Locale locale) {
|
public NumberFormat getNumberInstance(Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
NumberFormatProvider nfp = getImpl(locale);
|
NumberFormatProvider nfp = getImpl(locale);
|
||||||
return nfp.getNumberInstance(locale);
|
return nfp.getNumberInstance(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NumberFormat getPercentInstance(Locale locale) {
|
public NumberFormat getPercentInstance(Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
NumberFormatProvider nfp = getImpl(locale);
|
NumberFormatProvider nfp = getImpl(locale);
|
||||||
return nfp.getPercentInstance(locale);
|
return nfp.getPercentInstance(locale);
|
||||||
}
|
}
|
||||||
|
@ -379,38 +382,33 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
|
||||||
|
|
||||||
static class CalendarDataProviderDelegate extends CalendarDataProvider
|
static class CalendarDataProviderDelegate extends CalendarDataProvider
|
||||||
implements Delegate<CalendarDataProvider> {
|
implements Delegate<CalendarDataProvider> {
|
||||||
private final ConcurrentMap<Locale, CalendarDataProvider> map = new ConcurrentHashMap<>();
|
private final Map<Locale, CalendarDataProvider> map = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addImpl(CalendarDataProvider impl) {
|
public Map<Locale, CalendarDataProvider> getDelegateMap() {
|
||||||
for (Locale l : impl.getAvailableLocales()) {
|
return map;
|
||||||
map.putIfAbsent(l, impl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CalendarDataProvider getImpl(Locale locale) {
|
|
||||||
return SPILocaleProviderAdapter.getImpl(map, locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Locale[] getAvailableLocales() {
|
public Locale[] getAvailableLocales() {
|
||||||
return map.keySet().toArray(new Locale[0]);
|
return getAvailableLocalesDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupportedLocale(Locale locale) {
|
public boolean isSupportedLocale(Locale locale) {
|
||||||
return map.containsKey(locale);
|
return isSupportedLocaleDelegate(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFirstDayOfWeek(Locale locale) {
|
public int getFirstDayOfWeek(Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
CalendarDataProvider cdp = getImpl(locale);
|
CalendarDataProvider cdp = getImpl(locale);
|
||||||
return cdp.getFirstDayOfWeek(locale);
|
return cdp.getFirstDayOfWeek(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMinimalDaysInFirstWeek(Locale locale) {
|
public int getMinimalDaysInFirstWeek(Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
CalendarDataProvider cdp = getImpl(locale);
|
CalendarDataProvider cdp = getImpl(locale);
|
||||||
return cdp.getMinimalDaysInFirstWeek(locale);
|
return cdp.getMinimalDaysInFirstWeek(locale);
|
||||||
}
|
}
|
||||||
|
@ -418,34 +416,28 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
|
||||||
|
|
||||||
static class CalendarNameProviderDelegate extends CalendarNameProvider
|
static class CalendarNameProviderDelegate extends CalendarNameProvider
|
||||||
implements Delegate<CalendarNameProvider> {
|
implements Delegate<CalendarNameProvider> {
|
||||||
private final ConcurrentMap<Locale, CalendarNameProvider> map = new ConcurrentHashMap<>();
|
private final Map<Locale, CalendarNameProvider> map = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addImpl(CalendarNameProvider impl) {
|
public Map<Locale, CalendarNameProvider> getDelegateMap() {
|
||||||
for (Locale l : impl.getAvailableLocales()) {
|
return map;
|
||||||
map.putIfAbsent(l, impl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CalendarNameProvider getImpl(Locale locale) {
|
|
||||||
return SPILocaleProviderAdapter.getImpl(map, locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Locale[] getAvailableLocales() {
|
public Locale[] getAvailableLocales() {
|
||||||
return map.keySet().toArray(new Locale[0]);
|
return getAvailableLocalesDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupportedLocale(Locale locale) {
|
public boolean isSupportedLocale(Locale locale) {
|
||||||
return map.containsKey(locale);
|
return isSupportedLocaleDelegate(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName(String calendarType,
|
public String getDisplayName(String calendarType,
|
||||||
int field, int value,
|
int field, int value,
|
||||||
int style, Locale locale) {
|
int style, Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
CalendarNameProvider cdp = getImpl(locale);
|
CalendarNameProvider cdp = getImpl(locale);
|
||||||
return cdp.getDisplayName(calendarType, field, value, style, locale);
|
return cdp.getDisplayName(calendarType, field, value, style, locale);
|
||||||
}
|
}
|
||||||
|
@ -454,6 +446,7 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
|
||||||
public Map<String, Integer> getDisplayNames(String calendarType,
|
public Map<String, Integer> getDisplayNames(String calendarType,
|
||||||
int field, int style,
|
int field, int style,
|
||||||
Locale locale) {
|
Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
CalendarNameProvider cdp = getImpl(locale);
|
CalendarNameProvider cdp = getImpl(locale);
|
||||||
return cdp.getDisplayNames(calendarType, field, style, locale);
|
return cdp.getDisplayNames(calendarType, field, style, locale);
|
||||||
}
|
}
|
||||||
|
@ -461,38 +454,33 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
|
||||||
|
|
||||||
static class CurrencyNameProviderDelegate extends CurrencyNameProvider
|
static class CurrencyNameProviderDelegate extends CurrencyNameProvider
|
||||||
implements Delegate<CurrencyNameProvider> {
|
implements Delegate<CurrencyNameProvider> {
|
||||||
private final ConcurrentMap<Locale, CurrencyNameProvider> map = new ConcurrentHashMap<>();
|
private final Map<Locale, CurrencyNameProvider> map = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addImpl(CurrencyNameProvider impl) {
|
public Map<Locale, CurrencyNameProvider> getDelegateMap() {
|
||||||
for (Locale l : impl.getAvailableLocales()) {
|
return map;
|
||||||
map.putIfAbsent(l, impl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CurrencyNameProvider getImpl(Locale locale) {
|
|
||||||
return SPILocaleProviderAdapter.getImpl(map, locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Locale[] getAvailableLocales() {
|
public Locale[] getAvailableLocales() {
|
||||||
return map.keySet().toArray(new Locale[0]);
|
return getAvailableLocalesDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupportedLocale(Locale locale) {
|
public boolean isSupportedLocale(Locale locale) {
|
||||||
return map.containsKey(locale);
|
return isSupportedLocaleDelegate(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSymbol(String currencyCode, Locale locale) {
|
public String getSymbol(String currencyCode, Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
CurrencyNameProvider cnp = getImpl(locale);
|
CurrencyNameProvider cnp = getImpl(locale);
|
||||||
return cnp.getSymbol(currencyCode, locale);
|
return cnp.getSymbol(currencyCode, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName(String currencyCode, Locale locale) {
|
public String getDisplayName(String currencyCode, Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
CurrencyNameProvider cnp = getImpl(locale);
|
CurrencyNameProvider cnp = getImpl(locale);
|
||||||
return cnp.getDisplayName(currencyCode, locale);
|
return cnp.getDisplayName(currencyCode, locale);
|
||||||
}
|
}
|
||||||
|
@ -500,62 +488,61 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
|
||||||
|
|
||||||
static class LocaleNameProviderDelegate extends LocaleNameProvider
|
static class LocaleNameProviderDelegate extends LocaleNameProvider
|
||||||
implements Delegate<LocaleNameProvider> {
|
implements Delegate<LocaleNameProvider> {
|
||||||
private final ConcurrentMap<Locale, LocaleNameProvider> map = new ConcurrentHashMap<>();
|
private final Map<Locale, LocaleNameProvider> map = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addImpl(LocaleNameProvider impl) {
|
public Map<Locale, LocaleNameProvider> getDelegateMap() {
|
||||||
for (Locale l : impl.getAvailableLocales()) {
|
return map;
|
||||||
map.putIfAbsent(l, impl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocaleNameProvider getImpl(Locale locale) {
|
|
||||||
return SPILocaleProviderAdapter.getImpl(map, locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Locale[] getAvailableLocales() {
|
public Locale[] getAvailableLocales() {
|
||||||
return map.keySet().toArray(new Locale[0]);
|
return getAvailableLocalesDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupportedLocale(Locale locale) {
|
public boolean isSupportedLocale(Locale locale) {
|
||||||
return map.containsKey(locale);
|
return isSupportedLocaleDelegate(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayLanguage(String languageCode, Locale locale) {
|
public String getDisplayLanguage(String languageCode, Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
LocaleNameProvider lnp = getImpl(locale);
|
LocaleNameProvider lnp = getImpl(locale);
|
||||||
return lnp.getDisplayLanguage(languageCode, locale);
|
return lnp.getDisplayLanguage(languageCode, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayScript(String scriptCode, Locale locale) {
|
public String getDisplayScript(String scriptCode, Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
LocaleNameProvider lnp = getImpl(locale);
|
LocaleNameProvider lnp = getImpl(locale);
|
||||||
return lnp.getDisplayScript(scriptCode, locale);
|
return lnp.getDisplayScript(scriptCode, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayCountry(String countryCode, Locale locale) {
|
public String getDisplayCountry(String countryCode, Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
LocaleNameProvider lnp = getImpl(locale);
|
LocaleNameProvider lnp = getImpl(locale);
|
||||||
return lnp.getDisplayCountry(countryCode, locale);
|
return lnp.getDisplayCountry(countryCode, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayVariant(String variant, Locale locale) {
|
public String getDisplayVariant(String variant, Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
LocaleNameProvider lnp = getImpl(locale);
|
LocaleNameProvider lnp = getImpl(locale);
|
||||||
return lnp.getDisplayVariant(variant, locale);
|
return lnp.getDisplayVariant(variant, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayUnicodeExtensionKey(String key, Locale locale) {
|
public String getDisplayUnicodeExtensionKey(String key, Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
LocaleNameProvider lnp = getImpl(locale);
|
LocaleNameProvider lnp = getImpl(locale);
|
||||||
return lnp.getDisplayUnicodeExtensionKey(key, locale);
|
return lnp.getDisplayUnicodeExtensionKey(key, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayUnicodeExtensionType(String extType, String key, Locale locale) {
|
public String getDisplayUnicodeExtensionType(String extType, String key, Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
LocaleNameProvider lnp = getImpl(locale);
|
LocaleNameProvider lnp = getImpl(locale);
|
||||||
return lnp.getDisplayUnicodeExtensionType(extType, key, locale);
|
return lnp.getDisplayUnicodeExtensionType(extType, key, locale);
|
||||||
}
|
}
|
||||||
|
@ -563,38 +550,33 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
|
||||||
|
|
||||||
static class TimeZoneNameProviderDelegate extends TimeZoneNameProvider
|
static class TimeZoneNameProviderDelegate extends TimeZoneNameProvider
|
||||||
implements Delegate<TimeZoneNameProvider> {
|
implements Delegate<TimeZoneNameProvider> {
|
||||||
private final ConcurrentMap<Locale, TimeZoneNameProvider> map = new ConcurrentHashMap<>();
|
private final Map<Locale, TimeZoneNameProvider> map = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addImpl(TimeZoneNameProvider impl) {
|
public Map<Locale, TimeZoneNameProvider> getDelegateMap() {
|
||||||
for (Locale l : impl.getAvailableLocales()) {
|
return map;
|
||||||
map.putIfAbsent(l, impl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TimeZoneNameProvider getImpl(Locale locale) {
|
|
||||||
return SPILocaleProviderAdapter.getImpl(map, locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Locale[] getAvailableLocales() {
|
public Locale[] getAvailableLocales() {
|
||||||
return map.keySet().toArray(new Locale[0]);
|
return getAvailableLocalesDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupportedLocale(Locale locale) {
|
public boolean isSupportedLocale(Locale locale) {
|
||||||
return map.containsKey(locale);
|
return isSupportedLocaleDelegate(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName(String ID, boolean daylight, int style, Locale locale) {
|
public String getDisplayName(String ID, boolean daylight, int style, Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
TimeZoneNameProvider tznp = getImpl(locale);
|
TimeZoneNameProvider tznp = getImpl(locale);
|
||||||
return tznp.getDisplayName(ID, daylight, style, locale);
|
return tznp.getDisplayName(ID, daylight, style, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getGenericDisplayName(String ID, int style, Locale locale) {
|
public String getGenericDisplayName(String ID, int style, Locale locale) {
|
||||||
|
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||||
TimeZoneNameProvider tznp = getImpl(locale);
|
TimeZoneNameProvider tznp = getImpl(locale);
|
||||||
return tznp.getGenericDisplayName(ID, style, locale);
|
return tznp.getGenericDisplayName(ID, style, locale);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018, 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.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8208080
|
||||||
|
* @summary Tests DateFormatSymbols provider implementations
|
||||||
|
* @library provider
|
||||||
|
* @build provider/module-info provider/foo.DateFormatSymbolsProviderImpl
|
||||||
|
* @run main/othervm -Djava.locale.providers=SPI,CLDR DateFormatSymbolsProviderTests
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.text.DateFormatSymbols;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test DateFormatSymbolsProvider SPI with BCP47 U extensions
|
||||||
|
*/
|
||||||
|
public class DateFormatSymbolsProviderTests {
|
||||||
|
private static final Map<Locale, String> data = Map.of(
|
||||||
|
Locale.forLanguageTag("en-AA"), "foo",
|
||||||
|
Locale.forLanguageTag("en-US-u-rg-aazzzz"), "foo",
|
||||||
|
Locale.forLanguageTag("en-US-u-ca-japanese"), "bar"
|
||||||
|
);
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
data.forEach((l, e) -> {
|
||||||
|
DateFormatSymbols dfs = DateFormatSymbols.getInstance(l);
|
||||||
|
String[] months = dfs.getMonths();
|
||||||
|
System.out.printf("January string for locale %s is %s.%n", l.toString(), months[0]);
|
||||||
|
if (!months[0].equals(e)) {
|
||||||
|
throw new RuntimeException("DateFormatSymbols provider is not called for" + l);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018, 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.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package foo;
|
||||||
|
|
||||||
|
import java.text.DateFormatSymbols;
|
||||||
|
import java.text.spi.DateFormatSymbolsProvider;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Implements DateFormatSymbolsProvider SPI, in order to check if the
|
||||||
|
* extensions work correctly.
|
||||||
|
*/
|
||||||
|
public class DateFormatSymbolsProviderImpl extends DateFormatSymbolsProvider {
|
||||||
|
private static final Locale AA = Locale.forLanguageTag("en-AA");
|
||||||
|
private static final Locale USJCAL = Locale.forLanguageTag("en-US-u-ca-japanese");
|
||||||
|
private static final Locale[] avail = {AA, Locale.US};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Locale[] getAvailableLocales() {
|
||||||
|
return avail;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSupportedLocale(Locale l) {
|
||||||
|
// Overriding to check the relation between
|
||||||
|
// isSupportedLocale/getAvailableLocales works correctly
|
||||||
|
if (l.equals(AA)) {
|
||||||
|
// delegates to super, as if isSupportedLocale didn't exist.
|
||||||
|
return super.isSupportedLocale(l);
|
||||||
|
} else {
|
||||||
|
return (l.equals(USJCAL));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DateFormatSymbols getInstance(Locale l) {
|
||||||
|
return new MyDateFormatSymbols(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyDateFormatSymbols extends DateFormatSymbols {
|
||||||
|
Locale locale;
|
||||||
|
|
||||||
|
public MyDateFormatSymbols(Locale l) {
|
||||||
|
super(l);
|
||||||
|
locale = l;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getMonths() {
|
||||||
|
String[] ret = super.getMonths();
|
||||||
|
// replace the first item with some unique value
|
||||||
|
if (locale.stripExtensions().equals(AA)) {
|
||||||
|
ret[0] = "foo";
|
||||||
|
} else if (locale.equals(USJCAL)) {
|
||||||
|
ret[0] = "bar";
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Unsupported locale: " + locale);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -23,5 +23,6 @@
|
||||||
|
|
||||||
module provider {
|
module provider {
|
||||||
exports foo;
|
exports foo;
|
||||||
|
provides java.text.spi.DateFormatSymbolsProvider with foo.DateFormatSymbolsProviderImpl;
|
||||||
provides java.util.spi.LocaleNameProvider with foo.LocaleNameProviderImpl;
|
provides java.util.spi.LocaleNameProvider with foo.LocaleNameProviderImpl;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue