• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ZoneRulesProvider类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getTree

import java.time.zone.ZoneRulesProvider; //导入依赖的package包/类
protected PrefixTree getTree(DateTimeParseContext context) {
    // prepare parse tree
    Set<String> regionIds = ZoneRulesProvider.getAvailableZoneIds();
    final int regionIdsSize = regionIds.size();
    Entry<Integer, PrefixTree> cached = context.isCaseSensitive()
                                        ? cachedPrefixTree : cachedPrefixTreeCI;
    if (cached == null || cached.getKey() != regionIdsSize) {
        synchronized (this) {
            cached = context.isCaseSensitive() ? cachedPrefixTree : cachedPrefixTreeCI;
            if (cached == null || cached.getKey() != regionIdsSize) {
                cached = new SimpleImmutableEntry<>(regionIdsSize, PrefixTree.newTree(regionIds, context));
                if (context.isCaseSensitive()) {
                    cachedPrefixTree = cached;
                } else {
                    cachedPrefixTreeCI = cached;
                }
            }
        }
    }
    return cached.getValue();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:DateTimeFormatterBuilder.java


示例2: ofId

import java.time.zone.ZoneRulesProvider; //导入依赖的package包/类
/**
 * Obtains an instance of {@code ZoneId} from an identifier.
 *
 * @param zoneId  the time-zone ID, not null
 * @param checkAvailable  whether to check if the zone ID is available
 * @return the zone ID, not null
 * @throws DateTimeException if the ID format is invalid
 * @throws DateTimeException if checking availability and the ID cannot be found
 */
static ZoneRegion ofId(String zoneId, boolean checkAvailable) {
    Jdk8Methods.requireNonNull(zoneId, "zoneId");
    if (zoneId.length() < 2 || PATTERN.matcher(zoneId).matches() == false) {
        throw new DateTimeException("Invalid ID for region-based ZoneId, invalid format: " + zoneId);
    }
    ZoneRules rules = null;
    try {
        // always attempt load for better behavior after deserialization
        rules = ZoneRulesProvider.getRules(zoneId, true);
    } catch (ZoneRulesException ex) {
        // special case as removed from data file
        if (zoneId.equals("GMT0")) {
            rules = ZoneOffset.UTC.getRules();
        } else if (checkAvailable) {
            throw ex;
        }
    }
    return new ZoneRegion(zoneId, rules);
}
 
开发者ID:seratch,项目名称:java-time-backport,代码行数:29,代码来源:ZoneRegion.java


示例3: ofId

import java.time.zone.ZoneRulesProvider; //导入依赖的package包/类
/**
 * Obtains an instance of {@code ZoneId} from an identifier.
 * 
 * @param zoneId the time-zone ID, not null
 * @param checkAvailable whether to check if the zone ID is available
 * @return the zone ID, not null
 * @throws DateTimeException if the ID format is invalid
 * @throws DateTimeException if checking availability and the ID cannot be found
 */
static ZoneRegion ofId(String zoneId, boolean checkAvailable) {

  Jdk7Methods.Objects_requireNonNull(zoneId, "zoneId");
  if (zoneId.length() < 2 || zoneId.startsWith("UTC") || zoneId.startsWith("GMT")
      || (PATTERN.matcher(zoneId).matches() == false)) {
    throw new DateTimeException("ZoneId format is not a valid region format");
  }
  ZoneRules rules = null;
  try {
    // always attempt load for better behavior after deserialization
    rules = ZoneRulesProvider.getRules(zoneId);
  } catch (ZoneRulesException ex) {
    if (checkAvailable) {
      throw ex;
    }
  }
  return new ZoneRegion(zoneId, rules);
}
 
开发者ID:m-m-m,项目名称:java8-backports,代码行数:28,代码来源:ZoneRegion.java


示例4: ofId

import java.time.zone.ZoneRulesProvider; //导入依赖的package包/类
/**
 * Obtains an instance of {@code ZoneId} from an identifier.
 *
 * @param zoneId  the time-zone ID, not null
 * @param checkAvailable  whether to check if the zone ID is available
 * @return the zone ID, not null
 * @throws DateTimeException if the ID format is invalid
 * @throws ZoneRulesException if checking availability and the ID cannot be found
 */
static ZoneRegion ofId(String zoneId, boolean checkAvailable) {
    Objects.requireNonNull(zoneId, "zoneId");
    checkName(zoneId);
    ZoneRules rules = null;
    try {
        // always attempt load for better behavior after deserialization
        rules = ZoneRulesProvider.getRules(zoneId, true);
    } catch (ZoneRulesException ex) {
        if (checkAvailable) {
            throw ex;
        }
    }
    return new ZoneRegion(zoneId, rules);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:ZoneRegion.java


示例5: test_getAvailableGroupIds

import java.time.zone.ZoneRulesProvider; //导入依赖的package包/类
@Test
public void test_getAvailableGroupIds() {
    Set<String> zoneIds = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(zoneIds.contains("Europe/London"), true);
    zoneIds.clear();
    assertEquals(zoneIds.size(), 0);
    Set<String> zoneIds2 = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(zoneIds2.contains("Europe/London"), true);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:TCKZoneRulesProvider.java


示例6: test_getRules_StringBoolean

import java.time.zone.ZoneRulesProvider; //导入依赖的package包/类
@Test
public void test_getRules_StringBoolean() {
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertNotNull(rules);
    ZoneRules rules2 = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(rules2, rules);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKZoneRulesProvider.java


示例7: test_getRules_StringBoolean_dynamic

import java.time.zone.ZoneRulesProvider; //导入依赖的package包/类
@Test
public void test_getRules_StringBoolean_dynamic() {
    MockDynamicProvider dynamicProvider = new MockDynamicProvider();
    ZoneRulesProvider.registerProvider(dynamicProvider);

    assertEquals(dynamicProvider.count, 0);
    ZoneRules rules1 = ZoneId.of("DynamicLocation").getRules();
    assertEquals(dynamicProvider.count, 2);
    assertEquals(rules1, dynamicProvider.BASE);
    ZoneRules rules2 = ZoneId.of("DynamicLocation").getRules();
    assertEquals(dynamicProvider.count, 4);
    assertEquals(rules2, dynamicProvider.ALTERNATE);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:TCKZoneRulesProvider.java


示例8: test_getVersions_String

import java.time.zone.ZoneRulesProvider; //导入依赖的package包/类
@Test
public void test_getVersions_String() {
    NavigableMap<String, ZoneRules> versions = ZoneRulesProvider.getVersions("Europe/London");
    assertTrue(versions.size() >= 1);
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(versions.lastEntry().getValue(), rules);

    NavigableMap<String, ZoneRules> copy = new TreeMap<>(versions);
    versions.clear();
    assertEquals(versions.size(), 0);
    NavigableMap<String, ZoneRules> versions2 = ZoneRulesProvider.getVersions("Europe/London");
    assertEquals(versions2, copy);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:TCKZoneRulesProvider.java


示例9: test_registerProvider

import java.time.zone.ZoneRulesProvider; //导入依赖的package包/类
@Test
public void test_registerProvider() {
    Set<String> pre = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(pre.contains("FooLocation"), false);
    ZoneRulesProvider.registerProvider(new MockTempProvider());
    assertEquals(pre.contains("FooLocation"), false);
    Set<String> post = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(post.contains("FooLocation"), true);
    assertEquals(ZoneRulesProvider.getRules("FooLocation", false), ZoneOffset.of("+01:45").getRules());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:TCKZoneRulesProvider.java


示例10: test_printText

import java.time.zone.ZoneRulesProvider; //导入依赖的package包/类
public void test_printText() {
    Random r = RandomFactory.getRandom();
    int N = 8;
    Locale[] locales = Locale.getAvailableLocales();
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    ZonedDateTime zdt = ZonedDateTime.now();

    //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
    while (N-- > 0) {
        zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                 .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
        for (String zid : zids) {
            if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                continue;      // TBD: match jdk behavior?
            }
            zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
            TimeZone tz = TimeZone.getTimeZone(zid);
            boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
            for (Locale locale : locales) {
                String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
                String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
                if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
                        || (longDisplayName.startsWith("GMT-") && shortDisplayName.startsWith("GMT-"))) {
                    printText(locale, zdt, TextStyle.FULL, tz, tz.getID());
                    printText(locale, zdt, TextStyle.SHORT, tz, tz.getID());
                    continue;
                }
                printText(locale, zdt, TextStyle.FULL, tz,
                        tz.getDisplayName(isDST, TimeZone.LONG, locale));
                printText(locale, zdt, TextStyle.SHORT, tz,
                        tz.getDisplayName(isDST, TimeZone.SHORT, locale));
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:36,代码来源:TestZoneTextPrinterParser.java


示例11: test_ParseText

import java.time.zone.ZoneRulesProvider; //导入依赖的package包/类
public void test_ParseText() {
    Locale[] locales = new Locale[] { Locale.ENGLISH, Locale.JAPANESE, Locale.FRENCH };
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    for (Locale locale : locales) {
        parseText(zids, locale, TextStyle.FULL, false);
        parseText(zids, locale, TextStyle.FULL, true);
        parseText(zids, locale, TextStyle.SHORT, false);
        parseText(zids, locale, TextStyle.SHORT, true);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:TestZoneTextPrinterParser.java


示例12: test_printText

import java.time.zone.ZoneRulesProvider; //导入依赖的package包/类
public void test_printText() {
    Random r = RandomFactory.getRandom();
    int N = 8;
    Locale[] locales = Locale.getAvailableLocales();
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    ZonedDateTime zdt = ZonedDateTime.now();

    //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
    while (N-- > 0) {
        zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                 .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
        for (String zid : zids) {
            if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                continue;      // TBD: match jdk behavior?
            }
            zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
            TimeZone tz = TimeZone.getTimeZone(zid);
            boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
            for (Locale locale : locales) {
                printText(locale, zdt, TextStyle.FULL, tz,
                        tz.getDisplayName(isDST, TimeZone.LONG, locale));
                printText(locale, zdt, TextStyle.SHORT, tz,
                        tz.getDisplayName(isDST, TimeZone.SHORT, locale));
            }
        }
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:28,代码来源:TestZoneTextPrinterParser.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ExportMetricWriter类代码示例发布时间:2022-05-21
下一篇:
Java Context类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap