Search in sources :

Example 26 with ICUResourceBundle

use of android.icu.impl.ICUResourceBundle in project j2objc by google.

the class NumberingSystem method lookupInstanceByLocale.

static NumberingSystem lookupInstanceByLocale(LocaleLookupData localeLookupData) {
    ULocale locale = localeLookupData.locale;
    ICUResourceBundle rb;
    try {
        rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, locale);
        rb = rb.getWithFallback("NumberElements");
    } catch (MissingResourceException ex) {
        return new NumberingSystem();
    }
    String numbersKeyword = localeLookupData.numbersKeyword;
    String resolvedNumberingSystem = null;
    for (; ; ) {
        try {
            resolvedNumberingSystem = rb.getStringWithFallback(numbersKeyword);
            break;
        } catch (MissingResourceException ex) {
            // Fall back behavior as defined in TR35
            if (numbersKeyword.equals("native") || numbersKeyword.equals("finance")) {
                numbersKeyword = "default";
            } else if (numbersKeyword.equals("traditional")) {
                numbersKeyword = "native";
            } else {
                break;
            }
        }
    }
    NumberingSystem ns = null;
    if (resolvedNumberingSystem != null) {
        ns = getInstanceByName(resolvedNumberingSystem);
    }
    if (ns == null) {
        ns = new NumberingSystem();
    }
    return ns;
}
Also used : ULocale(android.icu.util.ULocale) MissingResourceException(java.util.MissingResourceException) ICUResourceBundle(android.icu.impl.ICUResourceBundle)

Example 27 with ICUResourceBundle

use of android.icu.impl.ICUResourceBundle in project j2objc by google.

the class RuleBasedNumberFormat method initCapitalizationContextInfo.

/**
 * Set capitalizationForListOrMenu, capitalizationForStandAlone
 */
private void initCapitalizationContextInfo(ULocale theLocale) {
    ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, theLocale);
    try {
        ICUResourceBundle rdb = rb.getWithFallback("contextTransforms/number-spellout");
        int[] intVector = rdb.getIntVector();
        if (intVector.length >= 2) {
            capitalizationForListOrMenu = (intVector[0] != 0);
            capitalizationForStandAlone = (intVector[1] != 0);
        }
    } catch (MissingResourceException e) {
    // use default
    }
}
Also used : MissingResourceException(java.util.MissingResourceException) ICUResourceBundle(android.icu.impl.ICUResourceBundle)

Example 28 with ICUResourceBundle

use of android.icu.impl.ICUResourceBundle in project j2objc by google.

the class DateFormatTest method TestCoverage.

@Test
public void TestCoverage() {
    Date now = new Date();
    Calendar cal = new GregorianCalendar();
    DateFormat f = DateFormat.getTimeInstance();
    logln("time: " + f.format(now));
    // sigh, everyone overrides this
    int hash = f.hashCode();
    f = DateFormat.getInstance(cal);
    if (hash == f.hashCode()) {
        errln("FAIL: hashCode equal for inequal objects");
    }
    logln("time again: " + f.format(now));
    f = DateFormat.getTimeInstance(cal, DateFormat.FULL);
    logln("time yet again: " + f.format(now));
    f = DateFormat.getDateInstance();
    logln("time yet again: " + f.format(now));
    ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "de_DE");
    DateFormatSymbols sym = new DateFormatSymbols(rb, Locale.GERMANY);
    DateFormatSymbols sym2 = (DateFormatSymbols) sym.clone();
    if (sym.hashCode() != sym2.hashCode()) {
        errln("fail, date format symbols hashcode not equal");
    }
    if (!sym.equals(sym2)) {
        errln("fail, date format symbols not equal");
    }
    Locale foo = new Locale("fu", "FU", "BAR");
    rb = null;
    sym = new DateFormatSymbols(GregorianCalendar.class, foo);
    sym.equals(null);
    sym = new ChineseDateFormatSymbols();
    sym = new ChineseDateFormatSymbols(new Locale("en_US"));
    try {
        sym = new ChineseDateFormatSymbols(null, new Locale("en_US"));
        errln("ChineseDateFormatSymbols(Calender, Locale) was suppose to return a null " + "pointer exception for a null paramater.");
    } catch (Exception e) {
    }
    sym = new ChineseDateFormatSymbols(new ChineseCalendar(), new Locale("en_US"));
    try {
        sym = new ChineseDateFormatSymbols(null, new ULocale("en_US"));
        errln("ChineseDateFormatSymbols(Calender, ULocale) was suppose to return a null " + "pointer exception for a null paramater.");
    } catch (Exception e) {
    }
    sym = new ChineseDateFormatSymbols(new ChineseCalendar(), foo);
    // cover new ChineseDateFormatSymbols(Calendar, ULocale)
    ChineseCalendar ccal = new ChineseCalendar();
    // gclsh1 add
    sym = new ChineseDateFormatSymbols(ccal, ULocale.CHINA);
    StringBuffer buf = new StringBuffer();
    FieldPosition pos = new FieldPosition(0);
    f.format((Object) cal, buf, pos);
    f.format((Object) now, buf, pos);
    f.format((Object) new Long(now.getTime()), buf, pos);
    try {
        f.format((Object) "Howdy", buf, pos);
    } catch (Exception e) {
    }
    NumberFormat nf = f.getNumberFormat();
    f.setNumberFormat(nf);
    boolean lenient = f.isLenient();
    f.setLenient(lenient);
    ULocale uloc = f.getLocale(ULocale.ACTUAL_LOCALE);
    DateFormat sdfmt = new SimpleDateFormat();
    if (f.hashCode() != f.hashCode()) {
        errln("hashCode is not stable");
    }
    if (!f.equals(f)) {
        errln("f != f");
    }
    if (f.equals(null)) {
        errln("f should not equal null");
    }
    if (f.equals(sdfmt)) {
        errln("A time instance shouldn't equal a default date format");
    }
    Date d;
    {
        ChineseDateFormat fmt = new ChineseDateFormat("yymm", Locale.US);
        try {
            // fewer symbols than required 2
            fmt.parse("2");
            errln("whoops");
        } catch (ParseException e) {
            logln("ok");
        }
        try {
            // should succeed with obeycount
            fmt.parse("2255");
            logln("ok");
        } catch (ParseException e) {
            errln("whoops");
        }
        try {
            // not a number, should fail
            fmt.parse("ni hao");
            errln("whoops ni hao");
        } catch (ParseException e) {
            logln("ok ni hao");
        }
    }
    {
        Calendar xcal = new GregorianCalendar();
        xcal.set(Calendar.HOUR_OF_DAY, 0);
        DateFormat fmt = new SimpleDateFormat("k");
        StringBuffer xbuf = new StringBuffer();
        FieldPosition fpos = new FieldPosition(Calendar.HOUR_OF_DAY);
        fmt.format(xcal, xbuf, fpos);
        try {
            fmt.parse(xbuf.toString());
            logln("ok");
            xbuf.setLength(0);
            xcal.set(Calendar.HOUR_OF_DAY, 25);
            fmt.format(xcal, xbuf, fpos);
            Date d2 = fmt.parse(xbuf.toString());
            logln("ok again - d2=" + d2);
        } catch (ParseException e) {
            errln("whoops");
        }
    }
    {
        // cover gmt+hh:mm
        DateFormat fmt = new SimpleDateFormat("MM/dd/yy z");
        try {
            d = fmt.parse("07/10/53 GMT+10:00");
            logln("ok : d = " + d);
        } catch (ParseException e) {
            errln("Parse of 07/10/53 GMT+10:00 for pattern MM/dd/yy z");
        }
        // cover invalid separator after GMT
        {
            ParsePosition pp = new ParsePosition(0);
            String text = "07/10/53 GMT=10:00";
            d = fmt.parse(text, pp);
            if (pp.getIndex() != 12) {
                errln("Parse of 07/10/53 GMT=10:00 for pattern MM/dd/yy z");
            }
            logln("Parsing of the text stopped at pos: " + pp.getIndex() + " as expected and length is " + text.length());
        }
        // cover bad text after GMT+.
        try {
            fmt.parse("07/10/53 GMT+blecch");
            logln("ok GMT+blecch");
        } catch (ParseException e) {
            errln("whoops GMT+blecch");
        }
        // cover bad text after GMT+hh:.
        try {
            fmt.parse("07/10/53 GMT+07:blecch");
            logln("ok GMT+xx:blecch");
        } catch (ParseException e) {
            errln("whoops GMT+xx:blecch");
        }
        // cover no ':' GMT+#, # < 24 (hh)
        try {
            d = fmt.parse("07/10/53 GMT+07");
            logln("ok GMT+07");
        } catch (ParseException e) {
            errln("Parse of 07/10/53 GMT+07 for pattern MM/dd/yy z");
        }
        // cover no ':' GMT+#, # > 24 (hhmm)
        try {
            d = fmt.parse("07/10/53 GMT+0730");
            logln("ok");
        } catch (ParseException e) {
            errln("Parse of 07/10/53 GMT+0730 for pattern MM/dd/yy z");
        }
        // cover GMT+#, # with second field
        try {
            d = fmt.parse("07/10/53 GMT+07:30:15");
            logln("ok GMT+07:30:15");
        } catch (ParseException e) {
            errln("Parse of 07/10/53 GMT+07:30:15 for pattern MM/dd/yy z");
        }
        // cover no ':' GMT+#, # with second field, no leading zero
        try {
            d = fmt.parse("07/10/53 GMT+73015");
            logln("ok GMT+73015");
        } catch (ParseException e) {
            errln("Parse of 07/10/53 GMT+73015 for pattern MM/dd/yy z");
        }
        // cover no ':' GMT+#, # with 1 digit second field
        try {
            d = fmt.parse("07/10/53 GMT+07300");
            logln("ok GMT+07300");
        } catch (ParseException e) {
            errln("Parse of 07/10/53 GMT+07300 for pattern MM/dd/yy z");
        }
        // cover raw digits with no leading sign (bad RFC822)
        try {
            d = fmt.parse("07/10/53 07");
            errln("Parse of 07/10/53 07 for pattern MM/dd/yy z passed!");
        } catch (ParseException e) {
            logln("ok");
        }
        // cover raw digits (RFC822)
        try {
            d = fmt.parse("07/10/53 +07");
            logln("ok");
        } catch (ParseException e) {
            errln("Parse of 07/10/53 +07 for pattern MM/dd/yy z failed");
        }
        // cover raw digits (RFC822)
        try {
            d = fmt.parse("07/10/53 -0730");
            logln("ok");
        } catch (ParseException e) {
            errln("Parse of 07/10/53 -00730 for pattern MM/dd/yy z failed");
        }
        // cover raw digits (RFC822) in DST
        try {
            fmt.setTimeZone(TimeZone.getTimeZone("PDT"));
            d = fmt.parse("07/10/53 -0730");
            logln("ok");
        } catch (ParseException e) {
            errln("Parse of 07/10/53 -0730 for pattern MM/dd/yy z failed");
        }
    }
    // TODO: revisit toLocalizedPattern
    if (false) {
        SimpleDateFormat fmt = new SimpleDateFormat("aabbcc");
        try {
            String pat = fmt.toLocalizedPattern();
            errln("whoops, shouldn't have been able to localize aabbcc");
        } catch (IllegalArgumentException e) {
            logln("aabbcc localize ok");
        }
    }
    {
        SimpleDateFormat fmt = new SimpleDateFormat("'aabbcc");
        try {
            fmt.toLocalizedPattern();
            errln("whoops, localize unclosed quote");
        } catch (IllegalArgumentException e) {
            logln("localize unclosed quote ok");
        }
    }
    {
        SimpleDateFormat fmt = new SimpleDateFormat("MM/dd/yy z");
        // bogus time zone
        String text = "08/15/58 DBDY";
        try {
            fmt.parse(text);
            errln("recognized bogus time zone DBDY");
        } catch (ParseException e) {
            logln("time zone ex ok");
        }
    }
    {
        // force fallback to default timezone when fmt timezone
        // is not named
        SimpleDateFormat fmt = new SimpleDateFormat("MM/dd/yy z");
        // force fallback to default time zone, still fails
        // not in equivalency group
        fmt.setTimeZone(TimeZone.getTimeZone("GMT+0147"));
        String text = "08/15/58 DBDY";
        try {
            fmt.parse(text);
            errln("Parse of 07/10/53 DBDY for pattern MM/dd/yy z passed");
        } catch (ParseException e) {
            logln("time zone ex2 ok");
        }
        // force success on fallback
        text = "08/15/58 " + TimeZone.getDefault().getDisplayName(true, TimeZone.SHORT);
        try {
            fmt.parse(text);
            logln("found default tz");
        } catch (ParseException e) {
            errln("whoops, got parse exception");
        }
    }
    {
        // force fallback to symbols list of timezones when neither
        // fmt and default timezone is named
        SimpleDateFormat fmt = new SimpleDateFormat("MM/dd/yy z");
        TimeZone oldtz = TimeZone.getDefault();
        // nonstandard tz
        TimeZone newtz = TimeZone.getTimeZone("GMT+0137");
        fmt.setTimeZone(newtz);
        // todo: fix security issue
        TimeZone.setDefault(newtz);
        // fallback to symbol list, but fail
        // try to parse the bogus time zone
        String text = "08/15/58 DBDY";
        try {
            fmt.parse(text);
            errln("Parse of 07/10/53 DBDY for pattern MM/dd/yy z passed");
        } catch (ParseException e) {
            logln("time zone ex3 ok");
        } catch (Exception e) {
            // hmmm... this shouldn't happen.  don't want to exit this
            // fn with timezone improperly set, so just in case
            TimeZone.setDefault(oldtz);
            throw new IllegalStateException(e.getMessage());
        }
    }
    {
        // cover getAvailableULocales
        final ULocale[] locales = DateFormat.getAvailableULocales();
        long count = locales.length;
        if (count == 0) {
            errln(" got a empty list for getAvailableULocales");
        } else {
            logln("" + count + " available ulocales");
        }
    }
    {
        // cover DateFormatSymbols.getDateFormatBundle
        cal = new GregorianCalendar();
        Locale loc = Locale.getDefault();
        DateFormatSymbols mysym = new DateFormatSymbols(cal, loc);
        if (mysym == null)
            errln("FAIL: constructs DateFormatSymbols with calendar and locale failed");
        uloc = ULocale.getDefault();
        // These APIs are obsolete and return null
        ResourceBundle resb = DateFormatSymbols.getDateFormatBundle(cal, loc);
        ResourceBundle resb2 = DateFormatSymbols.getDateFormatBundle(cal, uloc);
        ResourceBundle resb3 = DateFormatSymbols.getDateFormatBundle(cal.getClass(), loc);
        ResourceBundle resb4 = DateFormatSymbols.getDateFormatBundle(cal.getClass(), uloc);
        if (resb != null) {
            logln("resb is not null");
        }
        if (resb2 != null) {
            logln("resb2 is not null");
        }
        if (resb3 != null) {
            logln("resb3 is not null");
        }
        if (resb4 != null) {
            logln("resb4 is not null");
        }
    }
    {
        // cover DateFormatSymbols.getInstance
        DateFormatSymbols datsym1 = DateFormatSymbols.getInstance();
        DateFormatSymbols datsym2 = new DateFormatSymbols();
        if (!datsym1.equals(datsym2)) {
            errln("FAIL: DateFormatSymbols returned by getInstance()" + "does not match new DateFormatSymbols().");
        }
        datsym1 = DateFormatSymbols.getInstance(Locale.JAPAN);
        datsym2 = DateFormatSymbols.getInstance(ULocale.JAPAN);
        if (!datsym1.equals(datsym2)) {
            errln("FAIL: DateFormatSymbols returned by getInstance(Locale.JAPAN)" + "does not match the one returned by getInstance(ULocale.JAPAN).");
        }
    }
    {
        // cover DateFormatSymbols.getAvailableLocales/getAvailableULocales
        Locale[] allLocales = DateFormatSymbols.getAvailableLocales();
        if (allLocales.length == 0) {
            errln("FAIL: Got a empty list for DateFormatSymbols.getAvailableLocales");
        } else {
            logln("PASS: " + allLocales.length + " available locales returned by DateFormatSymbols.getAvailableLocales");
        }
        ULocale[] allULocales = DateFormatSymbols.getAvailableULocales();
        if (allULocales.length == 0) {
            errln("FAIL: Got a empty list for DateFormatSymbols.getAvailableLocales");
        } else {
            logln("PASS: " + allULocales.length + " available locales returned by DateFormatSymbols.getAvailableULocales");
        }
    }
}
Also used : Locale(java.util.Locale) ULocale(android.icu.util.ULocale) ChineseDateFormatSymbols(android.icu.text.ChineseDateFormatSymbols) ParsePosition(java.text.ParsePosition) ChineseCalendar(android.icu.util.ChineseCalendar) ULocale(android.icu.util.ULocale) BuddhistCalendar(android.icu.util.BuddhistCalendar) HebrewCalendar(android.icu.util.HebrewCalendar) IslamicCalendar(android.icu.util.IslamicCalendar) ChineseCalendar(android.icu.util.ChineseCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) Calendar(android.icu.util.Calendar) JapaneseCalendar(android.icu.util.JapaneseCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) ICUResourceBundle(android.icu.impl.ICUResourceBundle) FieldPosition(java.text.FieldPosition) Date(java.util.Date) ParseException(java.text.ParseException) IOException(java.io.IOException) TimeZone(android.icu.util.TimeZone) DateFormat(android.icu.text.DateFormat) ChineseDateFormat(android.icu.text.ChineseDateFormat) SimpleDateFormat(android.icu.text.SimpleDateFormat) DateFormatSymbols(android.icu.text.DateFormatSymbols) ChineseDateFormatSymbols(android.icu.text.ChineseDateFormatSymbols) ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) ResourceBundle(java.util.ResourceBundle) ParseException(java.text.ParseException) ChineseDateFormat(android.icu.text.ChineseDateFormat) SimpleDateFormat(android.icu.text.SimpleDateFormat) NumberFormat(android.icu.text.NumberFormat) Test(org.junit.Test)

Example 29 with ICUResourceBundle

use of android.icu.impl.ICUResourceBundle in project j2objc by google.

the class Collator method getKeywordValuesForLocale.

/**
 * <strong>[icu]</strong> Given a key and a locale, returns an array of string values in a preferred
 * order that would make a difference. These are all and only those values where
 * the open (creation) of the service with the locale formed from the input locale
 * plus input keyword and that value has different behavior than creation with the
 * input locale alone.
 * @param key           one of the keys supported by this service.  For now, only
 *                      "collation" is supported.
 * @param locale        the locale
 * @param commonlyUsed  if set to true it will return only commonly used values
 *                      with the given locale in preferred order.  Otherwise,
 *                      it will return all the available values for the locale.
 * @return an array of string values for the given key and the locale.
 */
public static final String[] getKeywordValuesForLocale(String key, ULocale locale, boolean commonlyUsed) {
    // Note: The parameter commonlyUsed is not used.
    // The switch is in the method signature for consistency
    // with other locale services.
    // Read available collation values from collation bundles.
    ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_COLLATION_BASE_NAME, locale);
    KeywordsSink sink = new KeywordsSink();
    bundle.getAllItemsWithFallback("collations", sink);
    return sink.values.toArray(new String[sink.values.size()]);
}
Also used : ICUResourceBundle(android.icu.impl.ICUResourceBundle)

Example 30 with ICUResourceBundle

use of android.icu.impl.ICUResourceBundle in project j2objc by google.

the class DateFormatSymbols method initializeData.

/**
 * Initializes format symbols for the locale and calendar type
 * @param desiredLocale The locale whose symbols are desired.
 * @param b Resource bundle provided externally
 * @param calendarType  The calendar type being used
 * @deprecated This API is ICU internal only.
 * @hide draft / provisional / internal are hidden on Android
 */
@Deprecated
protected // This API was accidentally marked as @stable ICU 3.0 formerly.
void initializeData(ULocale desiredLocale, ICUResourceBundle b, String calendarType) {
    // Create a CalendarSink to load this data and a resource bundle
    CalendarDataSink calendarSink = new CalendarDataSink();
    if (b == null) {
        b = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, desiredLocale);
    }
    // Iterate over the resource bundle data following the fallbacks through different calendar types
    while (calendarType != null) {
        // Enumerate this calendar type. If the calendar is not found fallback to gregorian.
        ICUResourceBundle dataForType = b.findWithFallback("calendar/" + calendarType);
        if (dataForType == null) {
            if (!"gregorian".equals(calendarType)) {
                calendarType = "gregorian";
                calendarSink.visitAllResources();
                continue;
            }
            throw new MissingResourceException("The 'gregorian' calendar type wasn't found for the locale: " + desiredLocale.getBaseName(), getClass().getName(), "gregorian");
        }
        calendarSink.preEnumerate(calendarType);
        dataForType.getAllItemsWithFallback("", calendarSink);
        // Stop loading when gregorian was loaded
        if (calendarType.equals("gregorian")) {
            break;
        }
        // Get the next calendar type to process from the sink
        calendarType = calendarSink.nextCalendarType;
        // Gregorian is always the last fallback
        if (calendarType == null) {
            calendarType = "gregorian";
            calendarSink.visitAllResources();
        }
    }
    Map<String, String[]> arrays = calendarSink.arrays;
    Map<String, Map<String, String>> maps = calendarSink.maps;
    eras = arrays.get("eras/abbreviated");
    eraNames = arrays.get("eras/wide");
    narrowEras = arrays.get("eras/narrow");
    months = arrays.get("monthNames/format/wide");
    shortMonths = arrays.get("monthNames/format/abbreviated");
    narrowMonths = arrays.get("monthNames/format/narrow");
    standaloneMonths = arrays.get("monthNames/stand-alone/wide");
    standaloneShortMonths = arrays.get("monthNames/stand-alone/abbreviated");
    standaloneNarrowMonths = arrays.get("monthNames/stand-alone/narrow");
    String[] lWeekdays = arrays.get("dayNames/format/wide");
    weekdays = new String[8];
    // 1-based
    weekdays[0] = "";
    System.arraycopy(lWeekdays, 0, weekdays, 1, lWeekdays.length);
    String[] aWeekdays = arrays.get("dayNames/format/abbreviated");
    shortWeekdays = new String[8];
    // 1-based
    shortWeekdays[0] = "";
    System.arraycopy(aWeekdays, 0, shortWeekdays, 1, aWeekdays.length);
    String[] sWeekdays = arrays.get("dayNames/format/short");
    shorterWeekdays = new String[8];
    // 1-based
    shorterWeekdays[0] = "";
    System.arraycopy(sWeekdays, 0, shorterWeekdays, 1, sWeekdays.length);
    String[] nWeekdays = arrays.get("dayNames/format/narrow");
    if (nWeekdays == null) {
        nWeekdays = arrays.get("dayNames/stand-alone/narrow");
        if (nWeekdays == null) {
            nWeekdays = arrays.get("dayNames/format/abbreviated");
            if (nWeekdays == null) {
                throw new MissingResourceException("Resource not found", getClass().getName(), "dayNames/format/abbreviated");
            }
        }
    }
    narrowWeekdays = new String[8];
    // 1-based
    narrowWeekdays[0] = "";
    System.arraycopy(nWeekdays, 0, narrowWeekdays, 1, nWeekdays.length);
    String[] swWeekdays = null;
    swWeekdays = arrays.get("dayNames/stand-alone/wide");
    standaloneWeekdays = new String[8];
    // 1-based
    standaloneWeekdays[0] = "";
    System.arraycopy(swWeekdays, 0, standaloneWeekdays, 1, swWeekdays.length);
    String[] saWeekdays = null;
    saWeekdays = arrays.get("dayNames/stand-alone/abbreviated");
    standaloneShortWeekdays = new String[8];
    // 1-based
    standaloneShortWeekdays[0] = "";
    System.arraycopy(saWeekdays, 0, standaloneShortWeekdays, 1, saWeekdays.length);
    String[] ssWeekdays = null;
    ssWeekdays = arrays.get("dayNames/stand-alone/short");
    standaloneShorterWeekdays = new String[8];
    // 1-based
    standaloneShorterWeekdays[0] = "";
    System.arraycopy(ssWeekdays, 0, standaloneShorterWeekdays, 1, ssWeekdays.length);
    String[] snWeekdays = null;
    snWeekdays = arrays.get("dayNames/stand-alone/narrow");
    standaloneNarrowWeekdays = new String[8];
    // 1-based
    standaloneNarrowWeekdays[0] = "";
    System.arraycopy(snWeekdays, 0, standaloneNarrowWeekdays, 1, snWeekdays.length);
    ampms = arrays.get("AmPmMarkers");
    ampmsNarrow = arrays.get("AmPmMarkersNarrow");
    quarters = arrays.get("quarters/format/wide");
    shortQuarters = arrays.get("quarters/format/abbreviated");
    standaloneQuarters = arrays.get("quarters/stand-alone/wide");
    standaloneShortQuarters = arrays.get("quarters/stand-alone/abbreviated");
    abbreviatedDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/abbreviated"));
    wideDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/wide"));
    narrowDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/narrow"));
    standaloneAbbreviatedDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/abbreviated"));
    standaloneWideDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/wide"));
    standaloneNarrowDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/narrow"));
    for (int i = 0; i < DT_MONTH_PATTERN_COUNT; i++) {
        String monthPatternPath = LEAP_MONTH_PATTERNS_PATHS[i];
        if (monthPatternPath != null) {
            Map<String, String> monthPatternMap = maps.get(monthPatternPath);
            if (monthPatternMap != null) {
                String leapMonthPattern = monthPatternMap.get("leap");
                if (leapMonthPattern != null) {
                    if (leapMonthPatterns == null) {
                        leapMonthPatterns = new String[DT_MONTH_PATTERN_COUNT];
                    }
                    leapMonthPatterns[i] = leapMonthPattern;
                }
            }
        }
    }
    shortYearNames = arrays.get("cyclicNameSets/years/format/abbreviated");
    shortZodiacNames = arrays.get("cyclicNameSets/zodiacs/format/abbreviated");
    requestedLocale = desiredLocale;
    ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, desiredLocale);
    localPatternChars = patternChars;
    // TODO: obtain correct actual/valid locale later
    ULocale uloc = rb.getULocale();
    setLocale(uloc, uloc);
    capitalization = new HashMap<CapitalizationContextUsage, boolean[]>();
    boolean[] noTransforms = new boolean[2];
    noTransforms[0] = false;
    noTransforms[1] = false;
    CapitalizationContextUsage[] allUsages = CapitalizationContextUsage.values();
    for (CapitalizationContextUsage usage : allUsages) {
        capitalization.put(usage, noTransforms);
    }
    UResourceBundle contextTransformsBundle = null;
    try {
        contextTransformsBundle = rb.getWithFallback("contextTransforms");
    } catch (MissingResourceException e) {
        // probably redundant
        contextTransformsBundle = null;
    }
    if (contextTransformsBundle != null) {
        UResourceBundleIterator ctIterator = contextTransformsBundle.getIterator();
        while (ctIterator.hasNext()) {
            UResourceBundle contextTransformUsage = ctIterator.next();
            int[] intVector = contextTransformUsage.getIntVector();
            if (intVector.length >= 2) {
                String usageKey = contextTransformUsage.getKey();
                CapitalizationContextUsage usage = contextUsageTypeMap.get(usageKey);
                if (usage != null) {
                    boolean[] transforms = new boolean[2];
                    transforms[0] = (intVector[0] != 0);
                    transforms[1] = (intVector[1] != 0);
                    capitalization.put(usage, transforms);
                }
            }
        }
    }
    NumberingSystem ns = NumberingSystem.getInstance(desiredLocale);
    // Latin is default.
    String nsName = ns == null ? "latn" : ns.getName();
    String tsPath = "NumberElements/" + nsName + "/symbols/timeSeparator";
    try {
        setTimeSeparatorString(rb.getStringWithFallback(tsPath));
    } catch (MissingResourceException e) {
        setTimeSeparatorString(DEFAULT_TIME_SEPARATOR);
    }
}
Also used : ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) UResourceBundleIterator(android.icu.util.UResourceBundleIterator) ULocale(android.icu.util.ULocale) MissingResourceException(java.util.MissingResourceException) ICUResourceBundle(android.icu.impl.ICUResourceBundle) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

ICUResourceBundle (android.icu.impl.ICUResourceBundle)42 MissingResourceException (java.util.MissingResourceException)21 ULocale (android.icu.util.ULocale)13 Test (org.junit.Test)11 UResourceBundle (android.icu.util.UResourceBundle)8 HashMap (java.util.HashMap)4 Locale (java.util.Locale)4 Map (java.util.Map)4 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 Calendar (android.icu.util.Calendar)2 HebrewCalendar (android.icu.util.HebrewCalendar)2 UResourceBundleIterator (android.icu.util.UResourceBundleIterator)2 ArrayList (java.util.ArrayList)2 Enumeration (java.util.Enumeration)2 TreeMap (java.util.TreeMap)2 ChineseDateFormat (android.icu.text.ChineseDateFormat)1 ChineseDateFormatSymbols (android.icu.text.ChineseDateFormatSymbols)1 DateFormat (android.icu.text.DateFormat)1 DateFormatSymbols (android.icu.text.DateFormatSymbols)1