Java Code Examples for sun.util.calendar.Era#getAbbreviation()

The following examples show how to use sun.util.calendar.Era#getAbbreviation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JapaneseImperialCalendar.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
@Override
public String getDisplayName(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }

    int fieldValue = get(field);

    // "GanNen" is supported only in the LONG style.
    if (field == YEAR
        && (getBaseStyle(style) != LONG || fieldValue != 1 || get(ERA) == 0)) {
        return null;
    }

    String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
                                                             fieldValue, style, locale);
    // If the ERA value is null, then
    // try to get its name or abbreviation from the Era instance.
    if (name == null && field == ERA && fieldValue < eras.length) {
        Era era = eras[fieldValue];
        name = (style == SHORT) ? era.getAbbreviation() : era.getName();
    }
    return name;
}
 
Example 2
Source File: JapaneseImperialCalendar.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String getDisplayName(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }

    int fieldValue = get(field);

    // "GanNen" is supported only in the LONG style.
    if (field == YEAR
        && (getBaseStyle(style) != LONG || fieldValue != 1 || get(ERA) == 0)) {
        return null;
    }

    String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
                                                             fieldValue, style, locale);
    // If the ERA value is null, then
    // try to get its name or abbreviation from the Era instance.
    if (name == null && field == ERA && fieldValue < eras.length) {
        Era era = eras[fieldValue];
        name = (style == SHORT) ? era.getAbbreviation() : era.getName();
    }
    return name;
}
 
Example 3
Source File: JapaneseImperialCalendar.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String getDisplayName(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }

    int fieldValue = get(field);

    // "GanNen" is supported only in the LONG style.
    if (field == YEAR
        && (getBaseStyle(style) != LONG || fieldValue != 1 || get(ERA) == 0)) {
        return null;
    }

    String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
                                                             fieldValue, style, locale);
    // If the ERA value is null, then
    // try to get its name or abbreviation from the Era instance.
    if (name == null && field == ERA && fieldValue < eras.length) {
        Era era = eras[fieldValue];
        name = (style == SHORT) ? era.getAbbreviation() : era.getName();
    }
    return name;
}
 
Example 4
Source File: JapaneseImperialCalendar.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
@Override
public String getDisplayName(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }

    int fieldValue = get(field);

    // "GanNen" is supported only in the LONG style.
    if (field == YEAR
        && (getBaseStyle(style) != LONG || fieldValue != 1 || get(ERA) == 0)) {
        return null;
    }

    String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
                                                             fieldValue, style, locale);
    // If the ERA value is null, then
    // try to get its name or abbreviation from the Era instance.
    if (name == null && field == ERA && fieldValue < eras.length) {
        Era era = eras[fieldValue];
        name = (style == SHORT) ? era.getAbbreviation() : era.getName();
    }
    return name;
}
 
Example 5
Source File: JapaneseImperialCalendar.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String getDisplayName(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }

    int fieldValue = get(field);

    // "GanNen" is supported only in the LONG style.
    if (field == YEAR
        && (getBaseStyle(style) != LONG || fieldValue != 1 || get(ERA) == 0)) {
        return null;
    }

    String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
                                                             fieldValue, style, locale);
    // If the ERA value is null, then
    // try to get its name or abbreviation from the Era instance.
    if (name == null && field == ERA && fieldValue < eras.length) {
        Era era = eras[fieldValue];
        name = (style == SHORT) ? era.getAbbreviation() : era.getName();
    }
    return name;
}
 
Example 6
Source File: JapaneseImperialCalendar.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
@Override
public String getDisplayName(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }

    int fieldValue = get(field);

    // "GanNen" is supported only in the LONG style.
    if (field == YEAR
        && (getBaseStyle(style) != LONG || fieldValue != 1 || get(ERA) == 0)) {
        return null;
    }

    String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
                                                             fieldValue, style, locale);
    // If the ERA value is null, then
    // try to get its name or abbreviation from the Era instance.
    if (name == null && field == ERA && fieldValue < eras.length) {
        Era era = eras[fieldValue];
        name = (style == SHORT) ? era.getAbbreviation() : era.getName();
    }
    return name;
}
 
Example 7
Source File: JapaneseImperialCalendar.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String getDisplayName(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }

    int fieldValue = get(field);

    // "GanNen" is supported only in the LONG style.
    if (field == YEAR
        && (getBaseStyle(style) != LONG || fieldValue != 1 || get(ERA) == 0)) {
        return null;
    }

    String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
                                                             fieldValue, style, locale);
    // If the ERA value is null, then
    // try to get its name or abbreviation from the Era instance.
    if (name == null && field == ERA && fieldValue < eras.length) {
        Era era = eras[fieldValue];
        name = (style == SHORT) ? era.getAbbreviation() : era.getName();
    }
    return name;
}
 
Example 8
Source File: JapaneseImperialCalendar.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String getDisplayName(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }

    int fieldValue = get(field);

    // "GanNen" is supported only in the LONG style.
    if (field == YEAR
        && (getBaseStyle(style) != LONG || fieldValue != 1 || get(ERA) == 0)) {
        return null;
    }

    String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
                                                             fieldValue, style, locale);
    // If the ERA value is null, then
    // try to get its name or abbreviation from the Era instance.
    if (name == null && field == ERA && fieldValue < eras.length) {
        Era era = eras[fieldValue];
        name = (style == SHORT) ? era.getAbbreviation() : era.getName();
    }
    return name;
}
 
Example 9
Source File: JapaneseImperialCalendar.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String getDisplayName(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }

    int fieldValue = get(field);

    // "GanNen" is supported only in the LONG style.
    if (field == YEAR
        && (getBaseStyle(style) != LONG || fieldValue != 1 || get(ERA) == 0)) {
        return null;
    }

    String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
                                                             fieldValue, style, locale);
    // If the ERA value is null, then
    // try to get its name or abbreviation from the Era instance.
    if (name == null && field == ERA && fieldValue < eras.length) {
        Era era = eras[fieldValue];
        name = (style == SHORT) ? era.getAbbreviation() : era.getName();
    }
    return name;
}
 
Example 10
Source File: JapaneseImperialCalendar.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getDisplayName(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }

    int fieldValue = get(field);

    // "GanNen" is supported only in the LONG style.
    if (field == YEAR
        && (getBaseStyle(style) != LONG || fieldValue != 1 || get(ERA) == 0)) {
        return null;
    }

    String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
                                                             fieldValue, style, locale);
    // If the ERA value is null or empty, then
    // try to get its name or abbreviation from the Era instance.
    if ((name == null || name.isEmpty()) &&
            field == ERA &&
            fieldValue < eras.length) {
        Era era = eras[fieldValue];
        name = (style == SHORT) ? era.getAbbreviation() : era.getName();
    }
    return name;
}
 
Example 11
Source File: JapaneseImperialCalendar.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
public String getDisplayName(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, SHORT, LONG, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }

    // "GanNen" is supported only in the LONG style.
    if (field == YEAR
        && (style == SHORT || get(YEAR) != 1 || get(ERA) == 0)) {
        return null;
    }

    ResourceBundle rb = LocaleData.getDateFormatData(locale);
    String name = null;
    String key = getKey(field, style);
    if (key != null) {
        String[] strings = rb.getStringArray(key);
        if (field == YEAR) {
            if (strings.length > 0) {
                name = strings[0];
            }
        } else {
            int index = get(field);
            // If the ERA value is out of range for strings, then
            // try to get its name or abbreviation from the Era instance.
            if (field == ERA && index >= strings.length && index < eras.length) {
                Era era = eras[index];
                name = (style == SHORT) ? era.getAbbreviation() : era.getName();
            } else {
                if (field == DAY_OF_WEEK)
                    --index;
                name = strings[index];
            }
        }
    }
    return name;
}
 
Example 12
Source File: JapaneseImperialCalendar.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public String getDisplayName(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }

    int fieldValue = get(field);

    // "GanNen" is supported only in the LONG style.
    if (field == YEAR
        && (getBaseStyle(style) != LONG || fieldValue != 1 || get(ERA) == 0)) {
        return null;
    }

    String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
                                                             fieldValue, style, locale);
    // If the ERA value is null or empty, then
    // try to get its name or abbreviation from the Era instance.
    if ((name == null || name.isEmpty()) &&
            field == ERA &&
            fieldValue < eras.length) {
        Era era = eras[fieldValue];
        name = (style == SHORT) ? era.getAbbreviation() : era.getName();
    }
    return name;
}
 
Example 13
Source File: CalendarNameProviderImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) {
    String name = null;
    String key = getResourceKey(calendarType, field, style, javatime);
    if (key != null) {
        LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
        String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
        if (strings != null && strings.length > 0) {
            if (field == DAY_OF_WEEK || field == YEAR) {
                --value;
            }
            if (value < 0 || value > strings.length) {
                return null;
            } else if (value == strings.length) {
                if (field == ERA && "japanese".equals(calendarType)) {
                    // get the supplemental era, if any, specified through
                    // the property "jdk.calendar.japanese.supplemental.era"
                    // which is always the last element.
                    Era[] jeras = CalendarSystem.forName("japanese").getEras();
                    if (jeras.length == value) {
                        Era supEra = jeras[value - 1]; // 0-based index
                        return style == LONG ?
                            supEra.getName() :
                            supEra.getAbbreviation();
                    }
                }
                return null;
            }
            name = strings[value];
            // If name is empty in standalone, try its `format' style.
            if (name.length() == 0
                    && (style == SHORT_STANDALONE || style == LONG_STANDALONE
                        || style == NARROW_STANDALONE)) {
                name = getDisplayName(calendarType, field, value,
                                      getBaseStyle(style),
                                      locale);
            }
        }
    }
    return name;
}
 
Example 14
Source File: JapaneseImperialCalendar.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
private Map<String,Integer> getDisplayNamesImpl(int field, int style, Locale locale) {
    ResourceBundle rb = LocaleData.getDateFormatData(locale);
    String key = getKey(field, style);
    Map<String,Integer> map = new HashMap<String,Integer>();
    if (key != null) {
        String[] strings = rb.getStringArray(key);
        if (field == YEAR) {
            if (strings.length > 0) {
                map.put(strings[0], 1);
            }
        } else {
            int base = (field == DAY_OF_WEEK) ? 1 : 0;
            for (int i = 0; i < strings.length; i++) {
                map.put(strings[i], base + i);
            }
            // If strings[] has fewer than eras[], get more names from eras[].
            if (field == ERA && strings.length < eras.length) {
                for (int i = strings.length; i < eras.length; i++) {
                    Era era = eras[i];
                    String name = (style == SHORT) ? era.getAbbreviation() : era.getName();
                    map.put(name, i);
                }
            }
        }
    }
    return map.size() > 0 ? map : null;
}
 
Example 15
Source File: JapaneseImperialCalendar.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getDisplayName(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }

    int fieldValue = get(field);

    // "GanNen" is supported only in the LONG style.
    if (field == YEAR
        && (getBaseStyle(style) != LONG || fieldValue != 1 || get(ERA) == 0)) {
        return null;
    }

    String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
                                                             fieldValue, style, locale);
    // If the ERA value is null or empty, then
    // try to get its name or abbreviation from the Era instance.
    if ((name == null || name.isEmpty()) &&
            field == ERA &&
            fieldValue < eras.length) {
        Era era = eras[fieldValue];
        name = (style == SHORT) ? era.getAbbreviation() : era.getName();
    }
    return name;
}
 
Example 16
Source File: CalendarNameProviderImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) {
    String name = null;
    String key = getResourceKey(calendarType, field, style, javatime);
    if (key != null) {
        LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
        String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
        if (strings != null && strings.length > 0) {
            if (field == DAY_OF_WEEK || field == YEAR) {
                --value;
            }
            if (value < 0) {
                return null;
            } else if (value >= strings.length) {
                if (field == ERA && "japanese".equals(calendarType)) {
                    Era[] jeras = CalendarSystem.forName("japanese").getEras();
                    if (value <= jeras.length) {
                        // Localized era name could not be retrieved from this provider.
                        // This can occur either for Reiwa or SupEra.
                        //
                        // If it's CLDR provider, try COMPAT first, which is guaranteed to have
                        // the name for Reiwa.
                        if (type == LocaleProviderAdapter.Type.CLDR) {
                            lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
                            key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE,
                                            calendarType, field, style, javatime);
                            strings =
                                javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
                        }
                        if (strings == null || value >= strings.length) {
                            // Get the default name for SupEra
                        Era supEra = jeras[value - 1]; // 0-based index
                            if (javatime) {
                                return getBaseStyle(style) == NARROW_FORMAT ?
                                    supEra.getAbbreviation() :
                                    supEra.getName();
                            } else {
                                return (style & LONG) != 0 ?
                            supEra.getName() :
                            supEra.getAbbreviation();
                    }
                }
                    } else {
                return null;
            }
                } else {
                    return null;
                }
            }
            name = strings[value];
            // If name is empty in standalone, try its `format' style.
            if (name.length() == 0
                    && (style == SHORT_STANDALONE || style == LONG_STANDALONE
                        || style == NARROW_STANDALONE)) {
                name = getDisplayName(calendarType, field, value,
                                      getBaseStyle(style),
                                      locale);
            }
        }
    }
    return name;
}
 
Example 17
Source File: CalendarNameProviderImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) {
    String name = null;
    String key = getResourceKey(calendarType, field, style, javatime);
    if (key != null) {
        LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
        String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);

        // If standalone names are requested and no "standalone." resources are found,
        // try the default ones instead.
        if (strings == null && key.indexOf("standalone.") != -1) {
            key = key.replaceFirst("standalone.", "");
            strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
        }

        if (strings != null && strings.length > 0) {
            if (field == DAY_OF_WEEK || field == YEAR) {
                --value;
            }
            if (value < 0 || value > strings.length) {
                return null;
            } else if (value == strings.length) {
                if (field == ERA && "japanese".equals(calendarType)) {
                    // get the supplemental era, if any, specified through
                    // the property "jdk.calendar.japanese.supplemental.era"
                    // which is always the last element.
                    Era[] jeras = CalendarSystem.forName("japanese").getEras();
                    if (jeras.length == value) {
                        Era supEra = jeras[value - 1]; // 0-based index
                        return style == LONG ?
                            supEra.getName() :
                            supEra.getAbbreviation();
                    }
                }
                return null;
            }
            name = strings[value];
            // If name is empty in standalone, try its `format' style.
            if (name.length() == 0
                    && (style == SHORT_STANDALONE || style == LONG_STANDALONE
                        || style == NARROW_STANDALONE)) {
                name = getDisplayName(calendarType, field, value,
                                      getBaseStyle(style),
                                      locale);
            }
        }
    }
    return name;
}
 
Example 18
Source File: CalendarNameProviderImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) {
    String name = null;
    String key = getResourceKey(calendarType, field, style, javatime);
    if (key != null) {
        LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
        String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
        if (strings != null && strings.length > 0) {
            if (field == DAY_OF_WEEK || field == YEAR) {
                --value;
            }
            if (value < 0) {
                return null;
            } else if (value >= strings.length) {
                if (field == ERA && "japanese".equals(calendarType)) {
                    Era[] jeras = CalendarSystem.forName("japanese").getEras();
                    if (value <= jeras.length) {
                        // Localized era name could not be retrieved from this provider.
                        // This can occur either for Reiwa or SupEra.
                        //
                        // If it's CLDR provider, try COMPAT first, which is guaranteed to have
                        // the name for Reiwa.
                        if (type == LocaleProviderAdapter.Type.CLDR) {
                            lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
                            key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE,
                                            calendarType, field, style, javatime);
                            strings =
                                javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
                        }
                        if (strings == null || value >= strings.length) {
                            // Get the default name for SupEra
                        Era supEra = jeras[value - 1]; // 0-based index
                            if (javatime) {
                                return getBaseStyle(style) == NARROW_FORMAT ?
                                    supEra.getAbbreviation() :
                                    supEra.getName();
                            } else {
                                return (style & LONG) != 0 ?
                            supEra.getName() :
                            supEra.getAbbreviation();
                    }
                }
                    } else {
                return null;
            }
                } else {
                    return null;
                }
            }
            name = strings[value];
            // If name is empty in standalone, try its `format' style.
            if (name.length() == 0
                    && (style == SHORT_STANDALONE || style == LONG_STANDALONE
                        || style == NARROW_STANDALONE)) {
                name = getDisplayName(calendarType, field, value,
                                      getBaseStyle(style),
                                      locale);
            }
        }
    }
    return name;
}
 
Example 19
Source File: CalendarNameProviderImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) {
    String name = null;
    String key = getResourceKey(calendarType, field, style, javatime);
    if (key != null) {
        LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
        String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
        if (strings != null && strings.length > 0) {
            if (field == DAY_OF_WEEK || field == YEAR) {
                --value;
            }
            if (value < 0) {
                return null;
            } else if (value >= strings.length) {
                if (field == ERA && "japanese".equals(calendarType)) {
                    Era[] jeras = CalendarSystem.forName("japanese").getEras();
                    if (value <= jeras.length) {
                        // Localized era name could not be retrieved from this provider.
                        // This can occur either for Reiwa or SupEra.
                        //
                        // If it's CLDR provider, try COMPAT first, which is guaranteed to have
                        // the name for Reiwa.
                        if (type == LocaleProviderAdapter.Type.CLDR) {
                            lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
                            key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE,
                                            calendarType, field, style, javatime);
                            strings =
                                javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
                        }
                        if (strings == null || value >= strings.length) {
                            // Get the default name for SupEra
                        Era supEra = jeras[value - 1]; // 0-based index
                            if (javatime) {
                                return getBaseStyle(style) == NARROW_FORMAT ?
                                    supEra.getAbbreviation() :
                                    supEra.getName();
                            } else {
                                return (style & LONG) != 0 ?
                            supEra.getName() :
                            supEra.getAbbreviation();
                    }
                }
                    } else {
                return null;
            }
                } else {
                    return null;
                }
            }
            name = strings[value];
            // If name is empty in standalone, try its `format' style.
            if (name.length() == 0
                    && (style == SHORT_STANDALONE || style == LONG_STANDALONE
                        || style == NARROW_STANDALONE)) {
                name = getDisplayName(calendarType, field, value,
                                      getBaseStyle(style),
                                      locale);
            }
        }
    }
    return name;
}
 
Example 20
Source File: CalendarNameProviderImpl.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) {
    String name = null;
    String key = getResourceKey(calendarType, field, style, javatime);
    if (key != null) {
        LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
        String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
        if (strings != null && strings.length > 0) {
            if (field == DAY_OF_WEEK || field == YEAR) {
                --value;
            }
            if (value < 0) {
                return null;
            } else if (value >= strings.length) {
                if (field == ERA && "japanese".equals(calendarType)) {
                    Era[] jeras = CalendarSystem.forName("japanese").getEras();
                    if (value <= jeras.length) {
                        // Localized era name could not be retrieved from this provider.
                        // This can occur either for Reiwa or SupEra.
                        //
                        // If it's CLDR provider, try COMPAT first, which is guaranteed to have
                        // the name for Reiwa.
                        if (type == LocaleProviderAdapter.Type.CLDR) {
                            lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
                            key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE,
                                            calendarType, field, style, javatime);
                            strings =
                                javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
                        }
                        if (strings == null || value >= strings.length) {
                            // Get the default name for SupEra
                        Era supEra = jeras[value - 1]; // 0-based index
                            if (javatime) {
                                return getBaseStyle(style) == NARROW_FORMAT ?
                                    supEra.getAbbreviation() :
                                    supEra.getName();
                            } else {
                                return (style & LONG) != 0 ?
                            supEra.getName() :
                            supEra.getAbbreviation();
                    }
                }
                    } else {
                return null;
            }
                } else {
                    return null;
                }
            }
            name = strings[value];
            // If name is empty in standalone, try its `format' style.
            if (name.length() == 0
                    && (style == SHORT_STANDALONE || style == LONG_STANDALONE
                        || style == NARROW_STANDALONE)) {
                name = getDisplayName(calendarType, field, value,
                                      getBaseStyle(style),
                                      locale);
            }
        }
    }
    return name;
}