本文整理汇总了Java中sun.util.locale.provider.TimeZoneNameUtility.retrieveGenericDisplayName方法的典型用法代码示例。如果您正苦于以下问题:Java TimeZoneNameUtility.retrieveGenericDisplayName方法的具体用法?Java TimeZoneNameUtility.retrieveGenericDisplayName怎么用?Java TimeZoneNameUtility.retrieveGenericDisplayName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.util.locale.provider.TimeZoneNameUtility
的用法示例。
在下文中一共展示了TimeZoneNameUtility.retrieveGenericDisplayName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDisplayName
import sun.util.locale.provider.TimeZoneNameUtility; //导入方法依赖的package包/类
private String getDisplayName(String id, int type, Locale locale) {
if (textStyle == TextStyle.NARROW) {
return null;
}
String[] names;
SoftReference<Map<Locale, String[]>> ref = cache.get(id);
Map<Locale, String[]> perLocale = null;
if (ref == null || (perLocale = ref.get()) == null ||
(names = perLocale.get(locale)) == null) {
names = TimeZoneNameUtility.retrieveDisplayNames(id, locale);
if (names == null) {
return null;
}
names = Arrays.copyOfRange(names, 0, 7);
names[5] =
TimeZoneNameUtility.retrieveGenericDisplayName(id, TimeZone.LONG, locale);
if (names[5] == null) {
names[5] = names[0]; // use the id
}
names[6] =
TimeZoneNameUtility.retrieveGenericDisplayName(id, TimeZone.SHORT, locale);
if (names[6] == null) {
names[6] = names[0];
}
if (perLocale == null) {
perLocale = new ConcurrentHashMap<>();
}
perLocale.put(locale, names);
cache.put(id, new SoftReference<>(perLocale));
}
switch (type) {
case STD:
return names[textStyle.zoneNameStyleIndex() + 1];
case DST:
return names[textStyle.zoneNameStyleIndex() + 3];
}
return names[textStyle.zoneNameStyleIndex() + 5];
}
示例2: test
import sun.util.locale.provider.TimeZoneNameUtility; //导入方法依赖的package包/类
private static void test(String tzid, int style, Locale locale, String expected) {
// No public API to get generic time zone names (JDK 8)
String got = TimeZoneNameUtility.retrieveGenericDisplayName(tzid, style, locale);
if (!expected.equals(got)) {
System.err.printf("test: tzid=%s, locale=%s, style=%d, got=\"%s\", expected=\"%s\"%n",
tzid, locale, style, got, expected);
errors++;
}
}
示例3: testGenericTZName
import sun.util.locale.provider.TimeZoneNameUtility; //导入方法依赖的package包/类
public static void testGenericTZName( Locale locale, String timezoneName,
int nameType, String expectedName ) throws RuntimeException {
if (testGeneric) {
String genericName = TimeZoneNameUtility.retrieveGenericDisplayName(timezoneName, nameType, locale);
//Check for equality
if (!genericName.equals(expectedName))
throw new RuntimeException( "Time zone ("+timezoneName+") name is incorrect for locale \""+locale.getDisplayName()
+"\" nameType: Generic"+"("+nameType+") Should be: " +expectedName+" Observed: "+genericName);
}
}