sun.util.calendar.Era Java Examples

The following examples show how to use sun.util.calendar.Era. 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 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 #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 openjdk-8 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 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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
Source File: JapaneseImperialCalendar.java    From jdk8u-dev-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 #12
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 #13
Source File: JapaneseImperialCalendar.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, ALL_STYLES, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }
    Map<String, Integer> names;
    names = CalendarDataUtility.retrieveFieldValueNames(getCalendarType(), field, style, locale);
    // If strings[] has fewer than eras[], get more names from eras[].
    if (names != null) {
        if (field == ERA) {
            int size = names.size();
            if (style == ALL_STYLES) {
                Set<Integer> values = new HashSet<>();
                // count unique era values
                for (String key : names.keySet()) {
                    values.add(names.get(key));
                }
                size = values.size();
            }
            if (size < eras.length) {
                int baseStyle = getBaseStyle(style);
                for (int i = size; i < eras.length; i++) {
                    Era era = eras[i];
                    if (baseStyle == ALL_STYLES || baseStyle == SHORT
                            || baseStyle == NARROW_FORMAT) {
                        names.put(era.getAbbreviation(), i);
                    }
                    if (baseStyle == ALL_STYLES || baseStyle == LONG) {
                        names.put(era.getName(), i);
                    }
                }
            }
        }
    }
    return names;
}
 
Example #14
Source File: JapaneseImperialCalendar.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, ALL_STYLES, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }
    Map<String, Integer> names;
    names = CalendarDataUtility.retrieveFieldValueNames(getCalendarType(), field, style, locale);
    // If strings[] has fewer than eras[], get more names from eras[].
    if (names != null) {
        if (field == ERA) {
            int size = names.size();
            if (style == ALL_STYLES) {
                Set<Integer> values = new HashSet<>();
                // count unique era values
                for (String key : names.keySet()) {
                    values.add(names.get(key));
                }
                size = values.size();
            }
            if (size < eras.length) {
                int baseStyle = getBaseStyle(style);
                for (int i = size; i < eras.length; i++) {
                    Era era = eras[i];
                    if (baseStyle == ALL_STYLES || baseStyle == SHORT
                            || baseStyle == NARROW_FORMAT) {
                        names.put(era.getAbbreviation(), i);
                    }
                    if (baseStyle == ALL_STYLES || baseStyle == LONG) {
                        names.put(era.getName(), i);
                    }
                }
            }
        }
    }
    return names;
}
 
Example #15
Source File: JapaneseImperialCalendar.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private static int getEraIndex(LocalGregorianCalendar.Date date) {
    Era era = date.getEra();
    for (int i = eras.length - 1; i > 0; i--) {
        if (eras[i] == era) {
            return i;
        }
    }
    return 0;
}
 
Example #16
Source File: JapaneseImperialCalendar.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static int getEraIndex(LocalGregorianCalendar.Date date) {
    Era era = date.getEra();
    for (int i = eras.length - 1; i > 0; i--) {
        if (eras[i] == era) {
            return i;
        }
    }
    return 0;
}
 
Example #17
Source File: JapaneseImperialCalendar.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, ALL_STYLES, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }
    Map<String, Integer> names;
    names = CalendarDataUtility.retrieveFieldValueNames(getCalendarType(), field, style, locale);
    // If strings[] has fewer than eras[], get more names from eras[].
    if (names != null) {
        if (field == ERA) {
            int size = names.size();
            if (style == ALL_STYLES) {
                Set<Integer> values = new HashSet<>();
                // count unique era values
                for (String key : names.keySet()) {
                    values.add(names.get(key));
                }
                size = values.size();
            }
            if (size < eras.length) {
                int baseStyle = getBaseStyle(style);
                for (int i = size; i < eras.length; i++) {
                    Era era = eras[i];
                    if (baseStyle == ALL_STYLES || baseStyle == SHORT
                            || baseStyle == NARROW_FORMAT) {
                        names.put(era.getAbbreviation(), i);
                    }
                    if (baseStyle == ALL_STYLES || baseStyle == LONG) {
                        names.put(era.getName(), i);
                    }
                }
            }
        }
    }
    return names;
}
 
Example #18
Source File: JapaneseImperialCalendar.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static int getEraIndex(LocalGregorianCalendar.Date date) {
    Era era = date.getEra();
    for (int i = eras.length - 1; i > 0; i--) {
        if (eras[i] == era) {
            return i;
        }
    }
    return 0;
}
 
Example #19
Source File: JapaneseImperialCalendar.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, ALL_STYLES, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }
    Map<String, Integer> names;
    names = CalendarDataUtility.retrieveFieldValueNames(getCalendarType(), field, style, locale);
    // If strings[] has fewer than eras[], get more names from eras[].
    if (names != null) {
        if (field == ERA) {
            int size = names.size();
            if (style == ALL_STYLES) {
                Set<Integer> values = new HashSet<>();
                // count unique era values
                for (String key : names.keySet()) {
                    values.add(names.get(key));
                }
                size = values.size();
            }
            if (size < eras.length) {
                int baseStyle = getBaseStyle(style);
                for (int i = size; i < eras.length; i++) {
                    Era era = eras[i];
                    if (baseStyle == ALL_STYLES || baseStyle == SHORT
                            || baseStyle == NARROW_FORMAT) {
                        names.put(era.getAbbreviation(), i);
                    }
                    if (baseStyle == ALL_STYLES || baseStyle == LONG) {
                        names.put(era.getName(), i);
                    }
                }
            }
        }
    }
    return names;
}
 
Example #20
Source File: JapaneseImperialCalendar.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, ALL_STYLES, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }
    Map<String, Integer> names;
    names = CalendarDataUtility.retrieveFieldValueNames(getCalendarType(), field, style, locale);
    // If strings[] has fewer than eras[], get more names from eras[].
    if (names != null) {
        if (field == ERA) {
            int size = names.size();
            if (style == ALL_STYLES) {
                Set<Integer> values = new HashSet<>();
                // count unique era values
                for (String key : names.keySet()) {
                    values.add(names.get(key));
                }
                size = values.size();
            }
            if (size < eras.length) {
                int baseStyle = getBaseStyle(style);
                for (int i = size; i < eras.length; i++) {
                    Era era = eras[i];
                    if (baseStyle == ALL_STYLES || baseStyle == SHORT
                            || baseStyle == NARROW_FORMAT) {
                        names.put(era.getAbbreviation(), i);
                    }
                    if (baseStyle == ALL_STYLES || baseStyle == LONG) {
                        names.put(era.getName(), i);
                    }
                }
            }
        }
    }
    return names;
}
 
Example #21
Source File: JapaneseImperialCalendar.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static int getEraIndex(LocalGregorianCalendar.Date date) {
    Era era = date.getEra();
    for (int i = eras.length - 1; i > 0; i--) {
        if (eras[i] == era) {
            return i;
        }
    }
    return 0;
}
 
Example #22
Source File: JapaneseImperialCalendar.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, ALL_STYLES, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }
    Map<String, Integer> names;
    names = CalendarDataUtility.retrieveFieldValueNames(getCalendarType(), field, style, locale);
    // If strings[] has fewer than eras[], get more names from eras[].
    if (names != null) {
        if (field == ERA) {
            int size = names.size();
            if (style == ALL_STYLES) {
                Set<Integer> values = new HashSet<>();
                // count unique era values
                for (String key : names.keySet()) {
                    values.add(names.get(key));
                }
                size = values.size();
            }
            if (size < eras.length) {
                int baseStyle = getBaseStyle(style);
                for (int i = 0; i < eras.length; i++) {
                    if (!names.values().contains(i)) {
                        Era era = eras[i];
                        if (baseStyle == ALL_STYLES || baseStyle == SHORT
                                || baseStyle == NARROW_FORMAT) {
                            names.put(era.getAbbreviation(), i);
                        }
                        if (baseStyle == ALL_STYLES || baseStyle == LONG) {
                            names.put(era.getName(), i);
                        }
                    }
                }
            }
        }
    }
    return names;
}
 
Example #23
Source File: JapaneseImperialCalendar.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static int getEraIndex(LocalGregorianCalendar.Date date) {
    Era era = date.getEra();
    for (int i = eras.length - 1; i > 0; i--) {
        if (eras[i] == era) {
            return i;
        }
    }
    return 0;
}
 
Example #24
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 #25
Source File: JapaneseImperialCalendar.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, ALL_STYLES, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }
    Map<String, Integer> names;
    names = CalendarDataUtility.retrieveFieldValueNames(getCalendarType(), field, style, locale);
    // If strings[] has fewer than eras[], get more names from eras[].
    if (names != null) {
        if (field == ERA) {
            int size = names.size();
            if (style == ALL_STYLES) {
                Set<Integer> values = new HashSet<>();
                // count unique era values
                for (String key : names.keySet()) {
                    values.add(names.get(key));
                }
                size = values.size();
            }
            if (size < eras.length) {
                int baseStyle = getBaseStyle(style);
                for (int i = size; i < eras.length; i++) {
                    Era era = eras[i];
                    if (baseStyle == ALL_STYLES || baseStyle == SHORT
                            || baseStyle == NARROW_FORMAT) {
                        names.put(era.getAbbreviation(), i);
                    }
                    if (baseStyle == ALL_STYLES || baseStyle == LONG) {
                        names.put(era.getName(), i);
                    }
                }
            }
        }
    }
    return names;
}
 
Example #26
Source File: JapaneseImperialCalendar.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static int getEraIndex(LocalGregorianCalendar.Date date) {
    Era era = date.getEra();
    for (int i = eras.length - 1; i > 0; i--) {
        if (eras[i] == era) {
            return i;
        }
    }
    return 0;
}
 
Example #27
Source File: JapaneseImperialCalendar.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, ALL_STYLES, NARROW_FORMAT, locale,
                                ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }
    Map<String, Integer> names;
    names = CalendarDataUtility.retrieveFieldValueNames(getCalendarType(), field, style, locale);
    // If strings[] has fewer than eras[], get more names from eras[].
    if (names != null) {
        if (field == ERA) {
            int size = names.size();
            if (style == ALL_STYLES) {
                Set<Integer> values = new HashSet<>();
                // count unique era values
                for (String key : names.keySet()) {
                    values.add(names.get(key));
                }
                size = values.size();
            }
            if (size < eras.length) {
                int baseStyle = getBaseStyle(style);
                for (int i = size; i < eras.length; i++) {
                    Era era = eras[i];
                    if (baseStyle == ALL_STYLES || baseStyle == SHORT
                            || baseStyle == NARROW_FORMAT) {
                        names.put(era.getAbbreviation(), i);
                    }
                    if (baseStyle == ALL_STYLES || baseStyle == LONG) {
                        names.put(era.getName(), i);
                    }
                }
            }
        }
    }
    return names;
}
 
Example #28
Source File: JapaneseImperialCalendar.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static int getEraIndex(LocalGregorianCalendar.Date date) {
    Era era = date.getEra();
    for (int i = eras.length - 1; i > 0; i--) {
        if (eras[i] == era) {
            return i;
        }
    }
    return 0;
}
 
Example #29
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 #30
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;
}