Search in sources :

Example 6 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class ZoneMeta method countEquivalentIDs.

/**
 * Returns the number of IDs in the equivalency group that
 * includes the given ID.  An equivalency group contains zones
 * that behave identically to the given zone.
 *
 * <p>If there are no equivalent zones, then this method returns
 * 0.  This means either the given ID is not a valid zone, or it
 * is and there are no other equivalent zones.
 * @param id a system time zone ID
 * @return the number of zones in the equivalency group containing
 * 'id', or zero if there are no equivalent zones.
 * @see #getEquivalentID
 */
public static synchronized int countEquivalentIDs(String id) {
    int count = 0;
    UResourceBundle res = openOlsonResource(null, id);
    if (res != null) {
        try {
            UResourceBundle links = res.get("links");
            int[] v = links.getIntVector();
            count = v.length;
        } catch (MissingResourceException ex) {
        // throw away
        }
    }
    return count;
}
Also used : UResourceBundle(android.icu.util.UResourceBundle) MissingResourceException(java.util.MissingResourceException)

Example 7 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class ZoneMeta method getCanonicalCLDRID.

/**
 * Return the canonical id for this tzid defined by CLDR, which might be
 * the id itself. If the given tzid is not known, return null.
 *
 * Note: This internal API supports all known system IDs and "Etc/Unknown" (which is
 * NOT a system ID).
 */
public static String getCanonicalCLDRID(String tzid) {
    String canonical = CANONICAL_ID_CACHE.get(tzid);
    if (canonical == null) {
        canonical = findCLDRCanonicalID(tzid);
        if (canonical == null) {
            // Resolve Olson link and try it again if necessary
            try {
                int zoneIdx = getZoneIndex(tzid);
                if (zoneIdx >= 0) {
                    UResourceBundle top = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, ZONEINFORESNAME, ICUResourceBundle.ICU_DATA_CLASS_LOADER);
                    UResourceBundle zones = top.get(kZONES);
                    UResourceBundle zone = zones.get(zoneIdx);
                    if (zone.getType() == UResourceBundle.INT) {
                        // It's a link - resolve link and lookup
                        tzid = getZoneID(zone.getInt());
                        canonical = findCLDRCanonicalID(tzid);
                    }
                    if (canonical == null) {
                        canonical = tzid;
                    }
                }
            } catch (MissingResourceException e) {
            // fall through
            }
        }
        if (canonical != null) {
            CANONICAL_ID_CACHE.put(tzid, canonical);
        }
    }
    return canonical;
}
Also used : UResourceBundle(android.icu.util.UResourceBundle) MissingResourceException(java.util.MissingResourceException)

Example 8 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class ZoneMeta method getShortIDFromCanonical.

private static String getShortIDFromCanonical(String canonicalID) {
    String shortID = null;
    String tzidKey = canonicalID.replace('/', ':');
    try {
        // First, try check if the given ID is canonical
        UResourceBundle keyTypeData = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "keyTypeData", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
        UResourceBundle typeMap = keyTypeData.get("typeMap");
        UResourceBundle typeKeys = typeMap.get("timezone");
        shortID = typeKeys.getString(tzidKey);
    } catch (MissingResourceException e) {
    // fall through
    }
    return shortID;
}
Also used : UResourceBundle(android.icu.util.UResourceBundle) MissingResourceException(java.util.MissingResourceException)

Example 9 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class ZoneMeta method openOlsonResource.

/**
 * Given an ID and the top-level resource of the zoneinfo resource,
 * open the appropriate resource for the given time zone.
 * Dereference links if necessary.
 * @param top the top level resource of the zoneinfo resource or null.
 * @param id zone id
 * @return the corresponding zone resource or null if not found
 */
public static UResourceBundle openOlsonResource(UResourceBundle top, String id) {
    UResourceBundle res = null;
    int zoneIdx = getZoneIndex(id);
    if (zoneIdx >= 0) {
        try {
            if (top == null) {
                top = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, ZONEINFORESNAME, ICUResourceBundle.ICU_DATA_CLASS_LOADER);
            }
            UResourceBundle zones = top.get(kZONES);
            UResourceBundle zone = zones.get(zoneIdx);
            if (zone.getType() == UResourceBundle.INT) {
                // resolve link
                zone = zones.get(zone.getInt());
            }
            res = zone;
        } catch (MissingResourceException e) {
            res = null;
        }
    }
    return res;
}
Also used : UResourceBundle(android.icu.util.UResourceBundle) MissingResourceException(java.util.MissingResourceException)

Example 10 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class ICUResourceBundle method getKeywordValues.

/**
 * Given a tree path and keyword, return a string enumeration of all possible values for that keyword.
 * @param baseName resource specifier
 * @param keyword a particular keyword to consider, must match a top level resource name
 * within the tree. (i.e. "collations")
 * @hide draft / provisional / internal are hidden on Android
 */
public static final String[] getKeywordValues(String baseName, String keyword) {
    Set<String> keywords = new HashSet<String>();
    ULocale[] locales = getAvailEntry(baseName, ICU_DATA_CLASS_LOADER).getULocaleList();
    int i;
    for (i = 0; i < locales.length; i++) {
        try {
            UResourceBundle b = UResourceBundle.getBundleInstance(baseName, locales[i]);
            // downcast to ICUResourceBundle?
            ICUResourceBundle irb = (ICUResourceBundle) (b.getObject(keyword));
            Enumeration<String> e = irb.getKeys();
            while (e.hasMoreElements()) {
                String s = e.nextElement();
                if (!DEFAULT_TAG.equals(s) && !s.startsWith("private-")) {
                    // don't add 'default' items, nor unlisted types
                    keywords.add(s);
                }
            }
        } catch (Throwable t) {
        // System.err.println("Error in - " + new Integer(i).toString()
        // + " - " + t.toString());
        // ignore the err - just skip that resource
        }
    }
    return keywords.toArray(new String[0]);
}
Also used : UResourceBundle(android.icu.util.UResourceBundle) ULocale(android.icu.util.ULocale) HashSet(java.util.HashSet)

Aggregations

UResourceBundle (android.icu.util.UResourceBundle)46 ICUResourceBundle (android.icu.impl.ICUResourceBundle)26 MissingResourceException (java.util.MissingResourceException)24 Test (org.junit.Test)17 ULocale (android.icu.util.ULocale)8 UResourceBundleIterator (android.icu.util.UResourceBundleIterator)6 UResourceTypeMismatchException (android.icu.util.UResourceTypeMismatchException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 SimpleTimeZone (android.icu.util.SimpleTimeZone)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 EnumSet (java.util.EnumSet)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 JavaTimeZone (android.icu.impl.JavaTimeZone)1