Search in sources :

Example 31 with UResourceBundle

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

the class KeyTypeData method getKeyInfo.

/**
 * Reads
 *keyInfo{
 *    deprecated{
 *        kh{"true"}
 *        vt{"true"}
 *    }
 *    valueType{
 *        ca{"incremental"}
 *        kr{"multiple"}
 *        vt{"multiple"}
 *        x0{"any"}
 *    }
 *}
 */
private static void getKeyInfo(UResourceBundle keyInfoRes) {
    Set<String> _deprecatedKeys = new LinkedHashSet<String>();
    Map<String, ValueType> _valueTypes = new LinkedHashMap<String, ValueType>();
    for (UResourceBundleIterator keyInfoIt = keyInfoRes.getIterator(); keyInfoIt.hasNext(); ) {
        UResourceBundle keyInfoEntry = keyInfoIt.next();
        String key = keyInfoEntry.getKey();
        KeyInfoType keyInfo = KeyInfoType.valueOf(key);
        for (UResourceBundleIterator keyInfoIt2 = keyInfoEntry.getIterator(); keyInfoIt2.hasNext(); ) {
            UResourceBundle keyInfoEntry2 = keyInfoIt2.next();
            String key2 = keyInfoEntry2.getKey();
            String value2 = keyInfoEntry2.getString();
            switch(keyInfo) {
                case deprecated:
                    _deprecatedKeys.add(key2);
                    break;
                case valueType:
                    _valueTypes.put(key2, ValueType.valueOf(value2));
                    break;
            }
        }
    }
    DEPRECATED_KEYS = Collections.unmodifiableSet(_deprecatedKeys);
    VALUE_TYPES = Collections.unmodifiableMap(_valueTypes);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) UResourceBundleIterator(android.icu.util.UResourceBundleIterator) LinkedHashMap(java.util.LinkedHashMap)

Example 32 with UResourceBundle

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

the class ZoneMeta method findCLDRCanonicalID.

private static String findCLDRCanonicalID(String tzid) {
    String canonical = null;
    String tzidKey = tzid.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");
        try {
            /* UResourceBundle canonicalEntry = */
            typeKeys.get(tzidKey);
            // The given tzid is available in the canonical list
            canonical = tzid;
        } catch (MissingResourceException e) {
        // fall through
        }
        if (canonical == null) {
            // Try alias map
            UResourceBundle typeAlias = keyTypeData.get("typeAlias");
            UResourceBundle aliasesForKey = typeAlias.get("timezone");
            canonical = aliasesForKey.getString(tzidKey);
        }
    } catch (MissingResourceException e) {
    // fall through
    }
    return canonical;
}
Also used : UResourceBundle(android.icu.util.UResourceBundle) MissingResourceException(java.util.MissingResourceException)

Example 33 with UResourceBundle

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

the class ZoneMeta method getZoneIDs.

/*
     * ICU frequently refers the zone ID array in zoneinfo resource
     */
private static synchronized String[] getZoneIDs() {
    if (ZONEIDS == null) {
        try {
            UResourceBundle top = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, ZONEINFORESNAME, ICUResourceBundle.ICU_DATA_CLASS_LOADER);
            ZONEIDS = top.getStringArray(kNAMES);
        } catch (MissingResourceException ex) {
        // throw away..
        }
    }
    if (ZONEIDS == null) {
        ZONEIDS = new String[0];
    }
    return ZONEIDS;
}
Also used : UResourceBundle(android.icu.util.UResourceBundle) MissingResourceException(java.util.MissingResourceException)

Example 34 with UResourceBundle

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

the class NumberingSystem method getAvailableNames.

/**
 * Returns a string array containing a list of the names of numbering systems
 * currently known to ICU.
 */
public static String[] getAvailableNames() {
    UResourceBundle numberingSystemsInfo = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "numberingSystems");
    UResourceBundle nsCurrent = numberingSystemsInfo.get("numberingSystems");
    UResourceBundle temp;
    String nsName;
    ArrayList<String> output = new ArrayList<String>();
    UResourceBundleIterator it = nsCurrent.getIterator();
    while (it.hasNext()) {
        temp = it.next();
        nsName = temp.getKey();
        output.add(nsName);
    }
    return output.toArray(new String[output.size()]);
}
Also used : UResourceBundle(android.icu.util.UResourceBundle) ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundleIterator(android.icu.util.UResourceBundleIterator) ArrayList(java.util.ArrayList)

Example 35 with UResourceBundle

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

the class OlsonTimeZone method construct.

private void construct(UResourceBundle top, UResourceBundle res) {
    if ((top == null || res == null)) {
        throw new IllegalArgumentException();
    }
    if (DEBUG)
        System.out.println("OlsonTimeZone(" + res.getKey() + ")");
    UResourceBundle r;
    int[] transPre32, trans32, transPost32;
    transPre32 = trans32 = transPost32 = null;
    transitionCount = 0;
    // Pre-32bit second transitions
    try {
        r = res.get("transPre32");
        transPre32 = r.getIntVector();
        if (transPre32.length % 2 != 0) {
            // elements in the pre-32bit must be an even number
            throw new IllegalArgumentException("Invalid Format");
        }
        transitionCount += transPre32.length / 2;
    } catch (MissingResourceException e) {
    // Pre-32bit transition data is optional
    }
    // 32bit second transitions
    try {
        r = res.get("trans");
        trans32 = r.getIntVector();
        transitionCount += trans32.length;
    } catch (MissingResourceException e) {
    // 32bit transition data is optional
    }
    // Post-32bit second transitions
    try {
        r = res.get("transPost32");
        transPost32 = r.getIntVector();
        if (transPost32.length % 2 != 0) {
            // elements in the post-32bit must be an even number
            throw new IllegalArgumentException("Invalid Format");
        }
        transitionCount += transPost32.length / 2;
    } catch (MissingResourceException e) {
    // Post-32bit transition data is optional
    }
    if (transitionCount > 0) {
        transitionTimes64 = new long[transitionCount];
        int idx = 0;
        if (transPre32 != null) {
            for (int i = 0; i < transPre32.length / 2; i++, idx++) {
                transitionTimes64[idx] = ((transPre32[i * 2]) & 0x00000000FFFFFFFFL) << 32 | ((transPre32[i * 2 + 1]) & 0x00000000FFFFFFFFL);
            }
        }
        if (trans32 != null) {
            for (int i = 0; i < trans32.length; i++, idx++) {
                transitionTimes64[idx] = trans32[i];
            }
        }
        if (transPost32 != null) {
            for (int i = 0; i < transPost32.length / 2; i++, idx++) {
                transitionTimes64[idx] = ((transPost32[i * 2]) & 0x00000000FFFFFFFFL) << 32 | ((transPost32[i * 2 + 1]) & 0x00000000FFFFFFFFL);
            }
        }
    } else {
        transitionTimes64 = null;
    }
    // Type offsets list must be of even size, with size >= 2
    r = res.get("typeOffsets");
    typeOffsets = r.getIntVector();
    if ((typeOffsets.length < 2 || typeOffsets.length > 0x7FFE || typeOffsets.length % 2 != 0)) {
        throw new IllegalArgumentException("Invalid Format");
    }
    typeCount = typeOffsets.length / 2;
    // Type map data must be of the same size as the transition count
    if (transitionCount > 0) {
        r = res.get("typeMap");
        typeMapData = r.getBinary(null);
        if (typeMapData == null || typeMapData.length != transitionCount) {
            throw new IllegalArgumentException("Invalid Format");
        }
    } else {
        typeMapData = null;
    }
    // Process final rule and data, if any
    finalZone = null;
    finalStartYear = Integer.MAX_VALUE;
    finalStartMillis = Double.MAX_VALUE;
    String ruleID = null;
    try {
        ruleID = res.getString("finalRule");
        r = res.get("finalRaw");
        int ruleRaw = r.getInt() * Grego.MILLIS_PER_SECOND;
        r = loadRule(top, ruleID);
        int[] ruleData = r.getIntVector();
        if (ruleData == null || ruleData.length != 11) {
            throw new IllegalArgumentException("Invalid Format");
        }
        finalZone = new SimpleTimeZone(ruleRaw, "", ruleData[0], ruleData[1], ruleData[2], ruleData[3] * Grego.MILLIS_PER_SECOND, ruleData[4], ruleData[5], ruleData[6], ruleData[7], ruleData[8] * Grego.MILLIS_PER_SECOND, ruleData[9], ruleData[10] * Grego.MILLIS_PER_SECOND);
        r = res.get("finalYear");
        finalStartYear = r.getInt();
        // Note: Setting finalStartYear to the finalZone is problematic.  When a date is around
        // year boundary, SimpleTimeZone may return false result when DST is observed at the
        // beginning of year.  We could apply safe margin (day or two), but when one of recurrent
        // rules falls around year boundary, it could return false result.  Without setting the
        // start year, finalZone works fine around the year boundary of the start year.
        // finalZone.setStartYear(finalStartYear);
        // Compute the millis for Jan 1, 0:00 GMT of the finalYear
        // Note: finalStartMillis is used for detecting either if
        // historic transition data or finalZone to be used.  In an
        // extreme edge case - for example, two transitions fall into
        // small windows of time around the year boundary, this may
        // result incorrect offset computation.  But I think it will
        // never happen practically.  Yoshito - Feb 20, 2010
        finalStartMillis = Grego.fieldsToDay(finalStartYear, 0, 1) * Grego.MILLIS_PER_DAY;
    } catch (MissingResourceException e) {
        if (ruleID != null) {
            // creating finalZone
            throw new IllegalArgumentException("Invalid Format");
        }
    }
}
Also used : UResourceBundle(android.icu.util.UResourceBundle) SimpleTimeZone(android.icu.util.SimpleTimeZone) MissingResourceException(java.util.MissingResourceException)

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