コード例 #1
0
  void test1() {
    Locale[] available = Locale.getAvailableLocales();
    List<Locale> jreimplloc =
        Arrays.asList(
            LocaleProviderAdapter.forJRE().getTimeZoneNameProvider().getAvailableLocales());
    List<Locale> providerLocales = Arrays.asList(tznp.getAvailableLocales());
    String[] ids = TimeZone.getAvailableIDs();

    for (Locale target : available) {
      // pure JRE implementation
      OpenListResourceBundle rb =
          ((ResourceBundleBasedAdapter) LocaleProviderAdapter.forJRE())
              .getLocaleData()
              .getTimeZoneNames(target);
      boolean jreSupportsTarget = jreimplloc.contains(target);

      for (String id : ids) {
        // the time zone
        TimeZone tz = TimeZone.getTimeZone(id);

        // JRE string array for the id
        String[] jrearray = null;
        if (jreSupportsTarget) {
          try {
            jrearray = rb.getStringArray(id);
          } catch (MissingResourceException mre) {
          }
        }

        for (int i = 1; i <= (tz.useDaylightTime() ? 4 : 2); i++) {
          // the localized name
          String name = tz.getDisplayName(i >= 3, i % 2, target);

          // provider's name (if any)
          String providersname = null;
          if (providerLocales.contains(target)) {
            providersname = tznp.getDisplayName(id, i >= 3, i % 2, target);
          }

          // JRE's name
          String jresname = null;
          if (jrearray != null) {
            jresname = jrearray[i];
          }

          checkValidity(
              target, jresname, providersname, name, jreSupportsTarget && jresname != null);
        }
      }
    }
  }
コード例 #2
0
 void test3() {
   final String[] TZNAMES = {
     LATIME, PST, PST8PDT, US_PACIFIC, TOKYOTIME, JST, JAPAN,
   };
   for (String tzname : TZNAMES) {
     TimeZone tz = TimeZone.getTimeZone(tzname);
     for (int style : new int[] {TimeZone.LONG, TimeZone.SHORT}) {
       String osakaStd = tz.getDisplayName(false, style, OSAKA);
       if (osakaStd != null) {
         // No API for getting generic time zone names
         String generic = TimeZoneNameUtility.retrieveGenericDisplayName(tzname, style, GENERIC);
         String expected = "Generic " + osakaStd;
         if (!expected.equals(generic)) {
           throw new RuntimeException(
               "Wrong generic name: got=\"" + generic + "\", expected=\"" + expected + "\"");
         }
       }
     }
   }
 }