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


Java ZoneRulesProvider.getAvailableZoneIds方法代码示例

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


在下文中一共展示了ZoneRulesProvider.getAvailableZoneIds方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: test_printText

import java.time.zone.ZoneRulesProvider; //导入方法依赖的package包/类
public void test_printText() {
    Random r = new Random();
    int N = 50;
    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:infobip,项目名称:infobip-open-jdk-8,代码行数:28,代码来源:TestZoneTextPrinterParser.java

示例8: test_getAvailableGroupIds

import java.time.zone.ZoneRulesProvider; //导入方法依赖的package包/类
@Test(groups = { "tck" })
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:m-m-m,项目名称:java8-backports,代码行数:11,代码来源:TCKZoneRulesProvider.java

示例9: test_registerProvider

import java.time.zone.ZoneRulesProvider; //导入方法依赖的package包/类
@Test(groups = { "tck" })
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"), ZoneOffset.of("+01:45").getRules());
}
 
开发者ID:m-m-m,项目名称:java8-backports,代码行数:13,代码来源:TCKZoneRulesProvider.java

示例10: test_getAvailableGroupIds

import java.time.zone.ZoneRulesProvider; //导入方法依赖的package包/类
@Test
public void test_getAvailableGroupIds() {
    Set<String> zoneIds = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(zoneIds.contains("Europe/London"), true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:TCKZoneRulesProvider.java

示例11: parse

import java.time.zone.ZoneRulesProvider; //导入方法依赖的package包/类
/**
 * This implementation looks for the longest matching string. For example, parsing Etc/GMT-2 will return
 * Etc/GMC-2 rather than just Etc/GMC although both are valid.
 * <p>
 * This implementation uses a tree to search for valid time-zone names in the parseText. The top level
 * node of the tree has a length equal to the length of the shortest time-zone as well as the beginning
 * characters of all other time-zones.
 */
@Override
public int parse(DateTimeParseContext context, CharSequence text, int position) {

  // TODO case insensitive?
  int length = text.length();
  if (position > length) {
    throw new IndexOutOfBoundsException();
  }

  // handle fixed time-zone IDs
  String remainder = text.subSequence(position, text.length()).toString();
  if (remainder.length() >= 1) {
    char nextChar = remainder.charAt(0);
    if (nextChar == '+' || nextChar == '-') {
      DateTimeParseContext newContext = new DateTimeParseContext(context.getLocale(),
          DateTimeFormatSymbols.STANDARD);
      int endPos = new ZoneOffsetPrinterParser("Z", "+HH:MM:ss").parse(newContext, text, position);
      if (endPos < 0) {
        return endPos;
      }
      int offset = (int) (long) newContext.getParsed(OFFSET_SECONDS);
      ZoneId zone = ZoneOffset.ofTotalSeconds(offset);
      context.setParsed(zone);
      return endPos;
    }
  }

  // prepare parse tree
  Set<String> regionIds = ZoneRulesProvider.getAvailableZoneIds();
  final int regionIdsSize = regionIds.size();
  Entry<Integer, SubstringTree> cached = cachedSubstringTree;
  if (cached == null || cached.getKey() != regionIdsSize) {
    synchronized (this) {
      cached = cachedSubstringTree;
      if (cached == null || cached.getKey() != regionIdsSize) {
        // cachedSubstringTree = cached = new SimpleImmutableEntry<>(regionIdsSize,
        // prepareParser(regionIds));
        cachedSubstringTree = cached = new SimpleImmutableEntry<Integer, SubstringTree>(regionIdsSize,
            prepareParser(regionIds));
      }
    }
  }
  SubstringTree tree = cached.getValue();

  // parse
  String parsedZoneId = null;
  while (tree != null) {
    int nodeLength = tree.length;
    if (position + nodeLength > length) {
      break;
    }
    parsedZoneId = text.subSequence(position, position + nodeLength).toString();
    tree = tree.get(parsedZoneId);
  }

  if (parsedZoneId == null || regionIds.contains(parsedZoneId) == false) {
    if (remainder.startsWith("Z")) {
      context.setParsed(ZoneOffset.UTC);
      return position + 1;
    }
    return ~position;
  }
  context.setParsed(ZoneId.of(parsedZoneId));
  return position + parsedZoneId.length();
}
 
开发者ID:m-m-m,项目名称:java8-backports,代码行数:74,代码来源:DateTimeFormatterBuilder.java

示例12: getAvailableZoneIds

import java.time.zone.ZoneRulesProvider; //导入方法依赖的package包/类
/**
 * Gets the set of available zone IDs.
 * <p>
 * This set includes the string form of all available region-based IDs.
 * Offset-based zone IDs are not included in the returned set.
 * The ID can be passed to {@link #of(String)} to create a {@code ZoneId}.
 * <p>
 * The set of zone IDs can increase over time, although in a typical application
 * the set of IDs is fixed. Each call to this method is thread-safe.
 *
 * @return a modifiable copy of the set of zone IDs, not null
 */
public static Set<String> getAvailableZoneIds() {
    return ZoneRulesProvider.getAvailableZoneIds();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:ZoneId.java

示例13: getAvailableZoneIds

import java.time.zone.ZoneRulesProvider; //导入方法依赖的package包/类
/**
 * Gets the set of available zone IDs.
 * <p>
 * This set includes the string form of all available region-based IDs.
 * Offset-based zone IDs are not included in the returned set.
 * The ID can be passed to {@link #of(String)} to create a {@code ZoneId}.
 * <p>
 * The set of zone IDs can increase over time, although in a typical application
 * the set of IDs is fixed. Each call to this method is thread-safe.
 *
 * @return a modifiable copy of the set of zone IDs, not null
 */
public static Set<String> getAvailableZoneIds() {
    return new HashSet<String>(ZoneRulesProvider.getAvailableZoneIds());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ZoneId.java


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