当前位置: 首页>>代码示例>>Java>>正文


Java CalendarDataUtility类代码示例

本文整理汇总了Java中sun.util.locale.provider.CalendarDataUtility的典型用法代码示例。如果您正苦于以下问题:Java CalendarDataUtility类的具体用法?Java CalendarDataUtility怎么用?Java CalendarDataUtility使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CalendarDataUtility类属于sun.util.locale.provider包,在下文中一共展示了CalendarDataUtility类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getText

import sun.util.locale.provider.CalendarDataUtility; //导入依赖的package包/类
/**
 * Gets the text for the specified chrono, field, locale and style
 * for the purpose of formatting.
 * <p>
 * The text associated with the value is returned.
 * The null return value should be used if there is no applicable text, or
 * if the text would be a numeric representation of the value.
 *
 * @param chrono  the Chronology to get text for, not null
 * @param field  the field to get text for, not null
 * @param value  the field value to get text for, not null
 * @param style  the style to get text for, not null
 * @param locale  the locale to get text for, not null
 * @return the text for the field value, null if no text found
 */
public String getText(Chronology chrono, TemporalField field, long value,
                                TextStyle style, Locale locale) {
    if (chrono == IsoChronology.INSTANCE
            || !(field instanceof ChronoField)) {
        return getText(field, value, style, locale);
    }

    int fieldIndex;
    int fieldValue;
    if (field == ERA) {
        fieldIndex = Calendar.ERA;
        if (chrono == JapaneseChronology.INSTANCE) {
            if (value == -999) {
                fieldValue = 0;
            } else {
                fieldValue = (int) value + 2;
            }
        } else {
            fieldValue = (int) value;
        }
    } else if (field == MONTH_OF_YEAR) {
        fieldIndex = Calendar.MONTH;
        fieldValue = (int) value - 1;
    } else if (field == DAY_OF_WEEK) {
        fieldIndex = Calendar.DAY_OF_WEEK;
        fieldValue = (int) value + 1;
        if (fieldValue > 7) {
            fieldValue = Calendar.SUNDAY;
        }
    } else if (field == AMPM_OF_DAY) {
        fieldIndex = Calendar.AM_PM;
        fieldValue = (int) value;
    } else {
        return null;
    }
    return CalendarDataUtility.retrieveJavaTimeFieldValueName(
            chrono.getCalendarType(), fieldIndex, fieldValue, style.toCalendarStyle(), locale);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:54,代码来源:DateTimeTextProvider.java

示例2: getDisplayName

import sun.util.locale.provider.CalendarDataUtility; //导入依赖的package包/类
@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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:JapaneseImperialCalendar.java

示例3: setWeekCountData

import sun.util.locale.provider.CalendarDataUtility; //导入依赖的package包/类
/**
 * Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent.
 * They are used to figure out the week count for a specific date for
 * a given locale. These must be set when a Calendar is constructed.
 * @param desiredLocale the given locale.
 */
private void setWeekCountData(Locale desiredLocale)
{
    /* try to get the Locale data from the cache */
    int[] data = cachedLocaleData.get(desiredLocale);
    if (data == null) {  /* cache miss */
        data = new int[2];
        data[0] = CalendarDataUtility.retrieveFirstDayOfWeek(desiredLocale);
        data[1] = CalendarDataUtility.retrieveMinimalDaysInFirstWeek(desiredLocale);
        cachedLocaleData.putIfAbsent(desiredLocale, data);
    }
    firstDayOfWeek = data[0];
    minimalDaysInFirstWeek = data[1];
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:Calendar.java

示例4: getDisplayNames

import sun.util.locale.provider.CalendarDataUtility; //导入依赖的package包/类
@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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:JapaneseImperialCalendar.java

示例5: getDisplayName

import sun.util.locale.provider.CalendarDataUtility; //导入依赖的package包/类
@Override
public String getDisplayName(int field, int style, Locale locale) {
    if (field != ERA) {
        return super.getDisplayName(field, style, locale);
    }

    return CalendarDataUtility.retrieveFieldValueName("buddhist", field, get(field), style, locale);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:BuddhistCalendar.java

示例6: getDisplayNames

import sun.util.locale.provider.CalendarDataUtility; //导入依赖的package包/类
@Override
public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) {
    if (field != ERA) {
        return super.getDisplayNames(field, style, locale);
    }
    return CalendarDataUtility.retrieveFieldValueNames("buddhist", field, style, locale);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:BuddhistCalendar.java

示例7: checkValueRange

import sun.util.locale.provider.CalendarDataUtility; //导入依赖的package包/类
private static void checkValueRange(String calType, int field, int value, int style, Locale l, boolean isNonNull) {
    String ret = CalendarDataUtility.retrieveJavaTimeFieldValueName(calType, field, value, style, l);
    System.out.print("retrieveFieldValueName("+calType+", "+field+", "+value+", "+style+", "+l+")");
    if ((ret != null) == isNonNull) {
        System.out.println(" returned "+ret);
    } else {
        throw new RuntimeException("The call returned "+ret);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:Bug8007038.java

示例8: getDisplayNames

import sun.util.locale.provider.CalendarDataUtility; //导入依赖的package包/类
@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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:JapaneseImperialCalendar.java

示例9: of

import sun.util.locale.provider.CalendarDataUtility; //导入依赖的package包/类
/**
 * Obtains an instance of {@code WeekFields} appropriate for a locale.
 * <p>
 * This will look up appropriate values from the provider of localization data.
 *
 * @param locale  the locale to use, not null
 * @return the week-definition, not null
 */
public static WeekFields of(Locale locale) {
    Objects.requireNonNull(locale, "locale");
    locale = new Locale(locale.getLanguage(), locale.getCountry());  // elminate variants

    int calDow = CalendarDataUtility.retrieveFirstDayOfWeek(locale);
    DayOfWeek dow = DayOfWeek.SUNDAY.plus(calDow - 1);
    int minDays = CalendarDataUtility.retrieveMinimalDaysInFirstWeek(locale);
    return WeekFields.of(dow, minDays);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:18,代码来源:WeekFields.java


注:本文中的sun.util.locale.provider.CalendarDataUtility类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。