mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8222756: Plural support in CompactNumberFormat
Reviewed-by: joehw, rriggs
This commit is contained in:
parent
3000f212f2
commit
730d0ecf19
18 changed files with 1101 additions and 130 deletions
|
@ -45,10 +45,14 @@ import java.text.DecimalFormat;
|
|||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.spi.NumberFormatProvider;
|
||||
import java.util.Arrays;
|
||||
import java.util.Currency;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import sun.text.resources.PluralRules;
|
||||
|
||||
/**
|
||||
* Concrete implementation of the {@link java.text.spi.NumberFormatProvider
|
||||
|
@ -69,6 +73,12 @@ public class NumberFormatProviderImpl extends NumberFormatProvider implements Av
|
|||
private final LocaleProviderAdapter.Type type;
|
||||
private final Set<String> langtags;
|
||||
|
||||
private static Map<String, String> rulesMap =
|
||||
Arrays.stream(PluralRules.rulesArray).collect(Collectors.toMap(
|
||||
sa -> sa[0],
|
||||
sa -> sa[1])
|
||||
);
|
||||
|
||||
public NumberFormatProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) {
|
||||
this.type = type;
|
||||
this.langtags = langtags;
|
||||
|
@ -271,8 +281,12 @@ public class NumberFormatProviderImpl extends NumberFormatProvider implements Av
|
|||
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(override);
|
||||
String[] cnPatterns = resource.getCNPatterns(formatStyle);
|
||||
|
||||
// plural rules
|
||||
String pluralRules = rulesMap.getOrDefault(override.toString(),
|
||||
rulesMap.getOrDefault(override.getLanguage(), ""));
|
||||
|
||||
CompactNumberFormat format = new CompactNumberFormat(numberPatterns[0],
|
||||
symbols, cnPatterns);
|
||||
symbols, cnPatterns, pluralRules);
|
||||
return format;
|
||||
}
|
||||
|
||||
|
|
|
@ -378,6 +378,14 @@ public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter {
|
|||
NumberFormatProvider nfp = getImpl(locale);
|
||||
return nfp.getPercentInstance(locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumberFormat getCompactNumberInstance(Locale locale,
|
||||
NumberFormat.Style style) {
|
||||
locale = CalendarDataUtility.findRegionOverride(locale);
|
||||
NumberFormatProvider nfp = getImpl(locale);
|
||||
return nfp.getCompactNumberInstance(locale, style);
|
||||
}
|
||||
}
|
||||
|
||||
static class CalendarDataProviderDelegate extends CalendarDataProvider
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue