src/java.base/macosx/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java
changeset 58972 dc998d4a227e
parent 47216 71c04702a3d5
child 59043 1a79b4bfc85a
equal deleted inserted replaced
58969:a4430bb9f97d 58972:dc998d4a227e
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    31 import java.text.spi.DateFormatSymbolsProvider;
    31 import java.text.spi.DateFormatSymbolsProvider;
    32 import java.text.spi.DecimalFormatSymbolsProvider;
    32 import java.text.spi.DecimalFormatSymbolsProvider;
    33 import java.text.spi.NumberFormatProvider;
    33 import java.text.spi.NumberFormatProvider;
    34 import java.util.Collections;
    34 import java.util.Collections;
    35 import java.util.Calendar;
    35 import java.util.Calendar;
       
    36 import java.util.HashMap;
    36 import java.util.HashSet;
    37 import java.util.HashSet;
    37 import java.util.Locale;
    38 import java.util.Locale;
    38 import java.util.Map;
    39 import java.util.Map;
    39 import java.util.ResourceBundle.Control;
    40 import java.util.ResourceBundle.Control;
    40 import java.util.Set;
    41 import java.util.Set;
   548             public boolean isSupportedLocale(Locale locale) {
   549             public boolean isSupportedLocale(Locale locale) {
   549                 return isSupportedCalendarLocale(locale);
   550                 return isSupportedCalendarLocale(locale);
   550             }
   551             }
   551 
   552 
   552             @Override
   553             @Override
   553             public String getDisplayName(String calType, int field, int value,
   554             public String getDisplayName(String calendarType, int field,
   554                                          int style, Locale locale) {
   555                                          int value, int style, Locale locale) {
   555                 return null;
   556                 String[] names = getCalendarDisplayStrings(locale.toLanguageTag(),
   556             }
   557                         field, style);
   557 
   558                 if (names != null && value >= 0 && value < names.length) {
   558             @Override
   559                     return names[value];
   559             public Map<String, Integer> getDisplayNames(String calType,
   560                 } else {
   560                                          int field, int style, Locale locale) {
   561                     return null;
   561                 return null;
   562                 }
       
   563             }
       
   564 
       
   565             @Override
       
   566             public Map<String, Integer> getDisplayNames(String calendarType,
       
   567                                                         int field, int style, Locale locale) {
       
   568                 Map<String, Integer> map = null;
       
   569                 String[] names = getCalendarDisplayStrings(locale.toLanguageTag(),
       
   570                         field, style);
       
   571                 if (names != null) {
       
   572                     map = new HashMap<>((int)Math.ceil(names.length / 0.75));
       
   573                     for (int value = 0; value < names.length; value++) {
       
   574                         if (names[value] != null) {
       
   575                             map.put(names[value], value);
       
   576                         }
       
   577                     }
       
   578                     map = map.isEmpty() ? null : map;
       
   579                 }
       
   580                 return map;
   562             }
   581             }
   563         };
   582         };
   564     }
   583     }
   565 
   584 
   566     public static CalendarProvider getCalendarProvider() {
   585     public static CalendarProvider getCalendarProvider() {
   899     private static native String getExponentSeparator(String langTag, String exponent);
   918     private static native String getExponentSeparator(String langTag, String exponent);
   900 
   919 
   901     // For CalendarDataProvider
   920     // For CalendarDataProvider
   902     private static native int getCalendarInt(String langTag, int type);
   921     private static native int getCalendarInt(String langTag, int type);
   903 
   922 
       
   923     // For CalendarNameProvider
       
   924     private static native String[] getCalendarDisplayStrings(String langTag, int field, int style);
       
   925 
   904     // For Locale/CurrencyNameProvider
   926     // For Locale/CurrencyNameProvider
   905     private static native String getDisplayString(String langTag, int key, String value);
   927     private static native String getDisplayString(String langTag, int key, String value);
   906 
   928 
   907     // For TimeZoneNameProvider
   929     // For TimeZoneNameProvider
   908     private static native String getTimeZoneDisplayString(String langTag, int style, String value);
   930     private static native String getTimeZoneDisplayString(String langTag, int style, String value);