sun.util.locale.provider.TimeZoneNameUtility Java Examples

The following examples show how to use sun.util.locale.provider.TimeZoneNameUtility. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DateFormatSymbols.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private String[][] getZoneStringsImpl(boolean needsCopy) {
    if (zoneStrings == null) {
        zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
    }

    if (!needsCopy) {
        return zoneStrings;
    }

    int len = zoneStrings.length;
    String[][] aCopy = new String[len][];
    for (int i = 0; i < len; i++) {
        aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
    }
    return aCopy;
}
 
Example #2
Source File: DateFormatSymbols.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private String[][] getZoneStringsImpl(boolean needsCopy) {
    if (zoneStrings == null) {
        zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
    }

    if (!needsCopy) {
        return zoneStrings;
    }

    int len = zoneStrings.length;
    String[][] aCopy = new String[len][];
    for (int i = 0; i < len; i++) {
        aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
    }
    return aCopy;
}
 
Example #3
Source File: DateFormatSymbols.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private String[][] getZoneStringsImpl(boolean needsCopy) {
    if (zoneStrings == null) {
        zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
    }

    if (!needsCopy) {
        return zoneStrings;
    }

    int len = zoneStrings.length;
    String[][] aCopy = new String[len][];
    for (int i = 0; i < len; i++) {
        aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
    }
    return aCopy;
}
 
Example #4
Source File: DateFormatSymbols.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private String[][] getZoneStringsImpl(boolean needsCopy) {
    if (zoneStrings == null) {
        zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
    }

    if (!needsCopy) {
        return zoneStrings;
    }

    int len = zoneStrings.length;
    String[][] aCopy = new String[len][];
    for (int i = 0; i < len; i++) {
        aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
    }
    return aCopy;
}
 
Example #5
Source File: DateFormatSymbols.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private String[][] getZoneStringsImpl(boolean needsCopy) {
    if (zoneStrings == null) {
        zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
    }

    if (!needsCopy) {
        return zoneStrings;
    }

    int len = zoneStrings.length;
    String[][] aCopy = new String[len][];
    for (int i = 0; i < len; i++) {
        aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
    }
    return aCopy;
}
 
Example #6
Source File: DateFormatSymbols.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private String[][] getZoneStringsImpl(boolean needsCopy) {
    if (zoneStrings == null) {
        zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
    }

    if (!needsCopy) {
        return zoneStrings;
    }

    int len = zoneStrings.length;
    String[][] aCopy = new String[len][];
    for (int i = 0; i < len; i++) {
        aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
    }
    return aCopy;
}
 
Example #7
Source File: DateFormatSymbols.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private String[][] getZoneStringsImpl(boolean needsCopy) {
    if (zoneStrings == null) {
        zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
    }

    if (!needsCopy) {
        return zoneStrings;
    }

    int len = zoneStrings.length;
    String[][] aCopy = new String[len][];
    for (int i = 0; i < len; i++) {
        aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
    }
    return aCopy;
}
 
Example #8
Source File: DateFormatSymbols.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private String[][] getZoneStringsImpl(boolean needsCopy) {
    if (zoneStrings == null) {
        zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
    }

    if (!needsCopy) {
        return zoneStrings;
    }

    int len = zoneStrings.length;
    String[][] aCopy = new String[len][];
    for (int i = 0; i < len; i++) {
        aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
    }
    return aCopy;
}
 
Example #9
Source File: DateFormatSymbols.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private String[][] getZoneStringsImpl(boolean needsCopy) {
    if (zoneStrings == null) {
        zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
    }

    if (!needsCopy) {
        return zoneStrings;
    }

    int len = zoneStrings.length;
    String[][] aCopy = new String[len][];
    for (int i = 0; i < len; i++) {
        aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
    }
    return aCopy;
}
 
Example #10
Source File: DateFormatSymbols.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private String[][] getZoneStringsImpl(boolean needsCopy) {
    if (zoneStrings == null) {
        zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
    }

    if (!needsCopy) {
        return zoneStrings;
    }

    int len = zoneStrings.length;
    String[][] aCopy = new String[len][];
    for (int i = 0; i < len; i++) {
        aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
    }
    return aCopy;
}
 
Example #11
Source File: DateFormatSymbols.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
private String[][] getZoneStringsImpl(boolean needsCopy) {
    if (zoneStrings == null) {
        zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
    }

    if (!needsCopy) {
        return zoneStrings;
    }

    int len = zoneStrings.length;
    String[][] aCopy = new String[len][];
    for (int i = 0; i < len; i++) {
        aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
    }
    return aCopy;
}
 
Example #12
Source File: SimpleDateFormat.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private int matchZoneString(String text, int start, String[] zoneNames) {
    for (int i = 1; i <= 4; ++i) {
        // Checking long and short zones [1 & 2],
        // and long and short daylight [3 & 4].
        String zoneName = zoneNames[i];
        if (zoneName.isEmpty()) {
            // fill in by retrieving single name
            zoneName = TimeZoneNameUtility.retrieveDisplayName(
                            zoneNames[0], i >= 3, i % 2, locale);
            zoneNames[i] = zoneName;
        }
        if (text.regionMatches(true, start,
                               zoneName, 0, zoneName.length())) {
            return i;
        }
    }
    return -1;
}
 
Example #13
Source File: DateFormatSymbols.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private String[][] getZoneStringsImpl(boolean needsCopy) {
    if (zoneStrings == null) {
        zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
    }

    if (!needsCopy) {
        return zoneStrings;
    }

    int len = zoneStrings.length;
    String[][] aCopy = new String[len][];
    for (int i = 0; i < len; i++) {
        aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
    }
    return aCopy;
}
 
Example #14
Source File: DateFormatSymbols.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private String[][] getZoneStringsImpl(boolean needsCopy) {
    if (zoneStrings == null) {
        zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
    }

    if (!needsCopy) {
        return zoneStrings;
    }

    int len = zoneStrings.length;
    String[][] aCopy = new String[len][];
    for (int i = 0; i < len; i++) {
        aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
    }
    return aCopy;
}
 
Example #15
Source File: DateTimeFormatterBuilder.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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];
}
 
Example #16
Source File: GenericTimeZoneNamesTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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++;
    }
}
 
Example #17
Source File: GenericTimeZoneNamesTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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++;
    }
}
 
Example #18
Source File: GenericTimeZoneNamesTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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++;
    }
}
 
Example #19
Source File: GenericTimeZoneNamesTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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++;
    }
}
 
Example #20
Source File: GenericTimeZoneNamesTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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++;
    }
}
 
Example #21
Source File: DateTimeFormatterBuilder.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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];
}
 
Example #22
Source File: DateTimeFormatterBuilder.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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];
}
 
Example #23
Source File: DateTimeFormatterBuilder.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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];
}
 
Example #24
Source File: GenericTimeZoneNamesTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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++;
    }
}
 
Example #25
Source File: GenericTimeZoneNamesTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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++;
    }
}
 
Example #26
Source File: DateFormatSymbols.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Write out the default serializable data, after ensuring the
 * {@code zoneStrings} field is initialized in order to make
 * sure the backward compatibility.
 *
 * @since 1.6
 */
@java.io.Serial
private void writeObject(ObjectOutputStream stream) throws IOException {
    if (zoneStrings == null) {
        zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
    }
    stream.defaultWriteObject();
}
 
Example #27
Source File: Locale.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private String getDisplayKeyTypeExtensionString(String key, LocaleResources lr, Locale inLocale) {
    String type = localeExtensions.getUnicodeLocaleType(key);
    String ret = getDisplayString(type, key, inLocale, DISPLAY_UEXT_TYPE);

    if (ret == null || ret.equals(type)) {
        // no localization for this type. try combining key/type separately
        String displayType = type;
        switch (key) {
        case "cu":
            displayType = lr.getCurrencyName(type.toLowerCase(Locale.ROOT));
            break;
        case "rg":
            if (type != null &&
                // UN M.49 code should not be allowed here
                type.matches("^[a-zA-Z]{2}[zZ]{4}$")) {
                    displayType = lr.getLocaleName(type.substring(0, 2).toUpperCase(Locale.ROOT));
            }
            break;
        case "tz":
            displayType = TimeZoneNameUtility.convertLDMLShortID(type)
                .map(id -> TimeZoneNameUtility.retrieveGenericDisplayName(id, TimeZone.LONG, inLocale))
                .orElse(type);
            break;
        }
        ret = MessageFormat.format(lr.getLocaleName("ListKeyTypePattern"),
            getDisplayString(key, null, inLocale, DISPLAY_UEXT_KEY),
            Optional.ofNullable(displayType).orElse(type));
    }

    return ret;
}
 
Example #28
Source File: Calendar.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private static TimeZone defaultTimeZone(Locale l) {
    TimeZone defaultTZ = TimeZone.getDefault();
    String shortTZID = l.getUnicodeLocaleType("tz");
    return shortTZID != null ?
        TimeZoneNameUtility.convertLDMLShortID(shortTZID)
            .map(TimeZone::getTimeZone)
            .orElse(defaultTZ) :
        defaultTZ;
}
 
Example #29
Source File: GenericTimeZoneNamesTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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++;
    }
}
 
Example #30
Source File: TimeZoneNamesTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}