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;
}
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;
}
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;
}
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;
}
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]);
}
Aggregations