Package com.ibm.icu.util

Examples of com.ibm.icu.util.ULocale$JDKLocaleHelper


        logln("Get a resource bundle " + baseName +
                " using GlobalizationPreferences initialized by locales - en_GB, en_US");
        GlobalizationPreferences gp = new GlobalizationPreferences();
        ULocale[] locales = new ULocale[2];
        locales[0] = new ULocale("en_GB");
        locales[1] = new ULocale("en_US");
        gp.setLocales(locales);

        try {
            rb = gp.getResourceBundle(baseName);
            String str = rb.getString("from_en_US");
            if (!str.equals("This data comes from en_US")) {
                errln("FAIL: from_en_US is not from en_US bundle");
            }
        } catch (MissingResourceException mre) {
            errln("FAIL: Missing resouces");
        }

        gp.reset();

        logln("Get a resource bundle " + baseName +
        " using GlobalizationPreferences initialized by locales - ja, en_US_California");

        locales = new ULocale[2];
        locales[0] = new ULocale("ja");
        locales[1] = new ULocale("en_US_California");
        gp.setLocales(locales);
       
        try {
            rb = gp.getResourceBundle(baseName, Thread.currentThread().getContextClassLoader());
            String str = rb.getString("from_en_US");
View Full Code Here


    public void TestTerritory() {
        GlobalizationPreferences gp = new GlobalizationPreferences();

        // Territory for unsupported language locale
        logln("Set locale - ang");
        gp.setLocale(new ULocale("ang"));
        String territory = gp.getTerritory();
        if (!territory.equals("US")) {
            errln("FAIL: Territory is " + territory + " - Expected: US");
        }

        // Territory for language only locale "fr"
        logln("Set locale - fr");
        gp.setLocale(new ULocale("fr"));
        territory = gp.getTerritory();
        if (!territory.equals("FR")) {
            errln("FAIL: Territory is " + territory + " - Expected: FR");
        }


        // Set explicity territory
        logln("Set explicit territory - CA");
        gp.setTerritory("CA");
        territory = gp.getTerritory();
        if (!territory.equals("CA")) {
            errln("FAIL: Territory is " + territory + " - Expected: CA");
        }

        // Freeze
        logln("Freeze this object");
        gp.freeze();
       
        boolean bFrozen = false;
        try {
            gp.setTerritory("FR");
        } catch (UnsupportedOperationException uoe) {
            logln("setTerritory is blocked");
            bFrozen = true;
        }
        if (!bFrozen) {
            errln("FAIL: setTerritory must be blocked after frozen");
        }
        territory = gp.getTerritory();
        if (!territory.equals("CA")) {
            errln("FAIL: Territory is not CA");
        }

        // Safe clone
        GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();
        territory = gp1.getTerritory();
        if (!territory.equals("CA")) {
            errln("FAIL: Territory is " + territory + " - Expected: CA");
        }

        gp1.reset();
        ULocale[] locales = new ULocale[2];
        locales[0] = new ULocale("ja");
        locales[1] = new ULocale("zh_Hant_TW");
        logln("Set locales - ja, zh_Hant_TW");
        gp1.setLocales(locales);

        territory = gp1.getTerritory();
View Full Code Here

    public void TestCurrency() {
        GlobalizationPreferences gp = new GlobalizationPreferences();

        // Set language only locale - ja
        logln("Set locale - ja");
        gp.setLocale(new ULocale("ja"));
        Currency cur = gp.getCurrency();
        String code = cur.getCurrencyCode();
        if (!code.equals("JPY")) {
            errln("FAIL: Currency is " + code + " - Expected: JPY");
        }

        gp.reset();
        // Set locales with territory
        logln("Set locale - ja_US");
        gp.setLocale(new ULocale("ja_US"));
        cur = gp.getCurrency();
        code = cur.getCurrencyCode();
        if (!code.equals("USD")) {
            errln("FAIL: Currency is " + code + " - Expected: USD");
        }

        // Set locales with territory in the second locale
        logln("Set locales - it, en_US");
        ULocale[] locales = new ULocale[2];
        locales[0] = new ULocale("it");
        locales[1] = new ULocale("en_US");
        gp.setLocales(locales);
        cur = gp.getCurrency();
        code = cur.getCurrencyCode();
        if (!code.equals("USD")) {
            errln("FAIL: Currency is " + code + " - Expected: USD");
View Full Code Here

    public void TestCalendar() {
        GlobalizationPreferences gp = new GlobalizationPreferences();

        // Set locale - pt_BR
        logln("Set locale - pt");
        gp.setLocale(new ULocale("pt"));
        Calendar cal = gp.getCalendar();
        String calType = cal.getType();
        if (!calType.equals("gregorian")) {
            errln("FAIL: Calendar type is " + calType + " Expected: gregorian");
        }

        // Set a list of locales
        logln("Set locales - en, en_JP, en_GB");
        ULocale[] locales = new ULocale[3];
        locales[0] = new ULocale("en");
        locales[1] = new ULocale("en_JP");
        locales[2] = new ULocale("en_GB");
        gp.setLocales(locales);

        cal = gp.getCalendar();
        ULocale calLocale = cal.getLocale(ULocale.VALID_LOCALE);
        if (!calLocale.equals(locales[2])) {
            errln("FAIL: Calendar locale is " + calLocale.toString() + " - Expected: en_GB");
        }

        // Set ecplicit calendar
        logln("Set Japanese calendar to this object");
        JapaneseCalendar jcal = new JapaneseCalendar();
View Full Code Here

                csp = UCaseProps.getSingleton();
            } catch(IOException e) {
                return this;
            }
            UnicodeSet foldSet = new UnicodeSet(this);
            ULocale root = ULocale.ROOT;

            // start with input set to guarantee inclusion
            // CASE: remove strings because the strings will actually be reduced (folded);
            //       therefore, start with no strings and add only those needed
            if((attribute & CASE) != 0) {
View Full Code Here

    public void TestTimeZone() {
        GlobalizationPreferences gp = new GlobalizationPreferences();

        // Set locale - zh_CN
        logln("Set locale - zh_CN");
        gp.setLocale(new ULocale("zh_CN"));
        TimeZone tz = gp.getTimeZone();
        String tzid = tz.getID();
        if (!tzid.equals("Asia/Shanghai")) {
            errln("FAIL: Time zone ID is " + tzid + " Expected: Asia/Shanghai");
        }

        // Set locale - en
        logln("Set locale - en");
        gp.setLocale(new ULocale("en"));
        tz = gp.getTimeZone();
        tzid = tz.getID();
        if (!tzid.equals("America/New_York")) {
            errln("FAIL: Time zone ID is " + tzid + " Expected: America/New_York");
        }
View Full Code Here

    public void TestCollator() {
        GlobalizationPreferences gp = new GlobalizationPreferences();

        // Set locale - tr
        logln("Set locale - tr");
        gp.setLocale(new ULocale("tr"));
        Collator coll = gp.getCollator();
        String locStr = coll.getLocale(ULocale.VALID_LOCALE).toString();
        if (!locStr.equals("tr")) {
            errln("FAIL: Collator locale is " + locStr + " Expected: tr");
        }

        // Unsupported collator locale - zun
        logln("Set locale - zun");
        gp.setLocale(new ULocale("zun"));
        coll = gp.getCollator();
        locStr = coll.getLocale(ULocale.VALID_LOCALE).toString();
        if (!locStr.equals("root")) {
            errln("FAIL: Collator locale is " + locStr + " Expected: root");
        }

        // Set locales - en_JP, fr, en_US, fr_FR
        logln("Set locale - en_JP, fr, en_US, fr_FR");
        ULocale[] locales = new ULocale[4];
        locales[0] = new ULocale("en_JP");
        locales[1] = new ULocale("fr");
        locales[2] = new ULocale("en_US");
        locales[3] = new ULocale("fr_FR");
        gp.setLocales(locales);
        coll = gp.getCollator();
        locStr = coll.getLocale(ULocale.VALID_LOCALE).toString();
        if (!locStr.equals("fr_FR")) {
            errln("FAIL: Collator locale is " + locStr + " Expected: fr_FR");
        }

        // Set explicit Collator
        Collator coll1 = Collator.getInstance(new ULocale("it"));
        coll1.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
        logln("Set collator for it in canonical deconposition mode");
        gp.setCollator(coll1);
        coll1.setStrength(Collator.IDENTICAL);
        coll = gp.getCollator();
View Full Code Here

    public void TestBreakIterator() {
        GlobalizationPreferences gp = new GlobalizationPreferences();

        // Unsupported break iterator locale - aar
        logln("Set locale - aar");
        gp.setLocale(new ULocale("aar"));
        BreakIterator brk = gp.getBreakIterator(GlobalizationPreferences.BI_LINE);
        String locStr = brk.getLocale(ULocale.VALID_LOCALE).toString();
        if (!locStr.equals("root")) {
            errln("FAIL: Line break iterator locale is " + locStr + " Expected: root");
        }

        // Set locale - es
        logln("Set locale - es");
        gp.setLocale(new ULocale("es"));
        brk = gp.getBreakIterator(GlobalizationPreferences.BI_CHARACTER);
        /* TODO: JB#5383
        locStr = brk.getLocale(ULocale.VALID_LOCALE).toString();
        if (!locStr.equals("es")) {
            errln("FAIL: Character break iterator locale is " + locStr + " Expected: es");
        }
        */

        // Set explicit break sentence iterator
        logln("Set break iterator for sentence using locale hu_HU");
        BreakIterator brk1 = BreakIterator.getSentenceInstance(new ULocale("hu_HU"));
        gp.setBreakIterator(GlobalizationPreferences.BI_SENTENCE, brk1);

        brk = gp.getBreakIterator(GlobalizationPreferences.BI_SENTENCE);
        /* TODO: JB#5210
        locStr = brk.getLocale(ULocale.VALID_LOCALE).toString();
        if (!locStr.equals("hu_HU")) {
            errln("FAIL: Sentence break locale is " + locStr + " Expected: hu_HU");
        }
        */
        brk.setText("This is a test case.  Is this a new instance?");
        brk.next();
        if (brk1.current() == brk.current()) {
            errln("FAIL: getBreakIterator must return a new instance");
        }

        // Illegal argument
        logln("Get break iterator type 100");
        boolean illegalArg = false;
        try {
            brk = gp.getBreakIterator(100);
        } catch (IllegalArgumentException iae) {
            logln("Break iterator type 100 is illegal");
            illegalArg = true;
        }
        if (!illegalArg) {
            errln("FAIL: getBreakIterator must throw IllegalArgumentException for type 100");
        }
        logln("Set break iterator type -1");
        illegalArg = false;
        try {
            gp.setBreakIterator(-1, brk1);
        } catch (IllegalArgumentException iae) {
            logln("Break iterator type -1 is illegal");
            illegalArg = true;
        }
        if (!illegalArg) {
            errln("FAIL: getBreakIterator must throw IllegalArgumentException for type -1");
        }

        // Freeze
        logln("Freeze this object");
        BreakIterator brk2 = BreakIterator.getTitleInstance(new ULocale("es_MX"));
        boolean isFrozen = false;
        gp.freeze();
        try {
            gp.setBreakIterator(GlobalizationPreferences.BI_TITLE, brk2);
        } catch (UnsupportedOperationException uoe) {
            logln("setBreakIterator is blocked");
            isFrozen = true;
        }
        if (!isFrozen) {
            errln("FAIL: setBreakIterator must be blocked after frozen");
        }

        // Modifiable clone
        logln("cloneAsThawed");
        GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();
        brk = gp1.getBreakIterator(GlobalizationPreferences.BI_WORD);
        /* TODO: JB#5383
        locStr = brk.getLocale(ULocale.VALID_LOCALE).toString();
        if (!locStr.equals("es")) {
            errln("FAIL: Word break iterator locale is " + locStr + " Expected: es");
        }
        */

        ULocale frFR = new ULocale("fr_FR");
        BreakIterator brkC = BreakIterator.getCharacterInstance(frFR);
        BreakIterator brkW = BreakIterator.getWordInstance(frFR);
        BreakIterator brkL = BreakIterator.getLineInstance(frFR);
        BreakIterator brkS = BreakIterator.getSentenceInstance(frFR);
        BreakIterator brkT = BreakIterator.getTitleInstance(frFR);
View Full Code Here

    }

    public void TestDisplayName() {
        GlobalizationPreferences gp = new GlobalizationPreferences();

        ULocale loc_fr_FR_Paris = new ULocale("fr_FR_Paris");
        ULocale loc_peo = new ULocale("peo");

        // Locale list - fr_FR_Paris
        ArrayList locales1 = new ArrayList(1);
        locales1.add(loc_fr_FR_Paris);
View Full Code Here

        String pattern;
        DateFormat df;

        // Set unsupported locale - ach
        logln("Set locale - ach");
        gp.setLocale(new ULocale("ach"));

        // Date - short
        df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT, GlobalizationPreferences.DF_NONE);
        pattern = ((SimpleDateFormat)df).toPattern();
        // root pattern must be used
        if (!pattern.equals("yyyy-MM-dd")) {
            errln("FAIL: SHORT date pattern is " + pattern + " Expected: yyyy-MM-dd");
        }

        // Set locale - fr, fr_CA, fr_FR
        ArrayList lcls = new ArrayList(3);
        lcls.add(new ULocale("fr"));
        lcls.add(new ULocale("fr_CA"));
        lcls.add(new ULocale("fr_FR"));
        logln("Set locales - fr, fr_CA, fr_FR");
        gp.setLocales(lcls);
        // Date - short
        df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT, GlobalizationPreferences.DF_NONE);
        pattern = ((SimpleDateFormat)df).toPattern();
        // fr_CA pattern must be used
        if (!pattern.equals("yy-MM-dd")) {
            errln("FAIL: SHORT date pattern is " + pattern + " Expected: yy-MM-dd");
        }


        // Set locale - en_GB
        logln("Set locale - en_GB");
        gp.setLocale(new ULocale("en_GB"));
       
        // Date - full
        df = gp.getDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_NONE);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("EEEE, d MMMM y")) {
            errln("FAIL: FULL date pattern is " + pattern + " Expected: EEEE, d MMMM y");
        }

        // Date - long
        df = gp.getDateFormat(GlobalizationPreferences.DF_LONG, GlobalizationPreferences.DF_NONE);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("d MMMM y")) {
            errln("FAIL: LONG date pattern is " + pattern + " Expected: d MMMM y");
        }

        // Date - medium
        df = gp.getDateFormat(GlobalizationPreferences.DF_MEDIUM, GlobalizationPreferences.DF_NONE);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("d MMM y")) {
            errln("FAIL: MEDIUM date pattern is " + pattern + " Expected: d MMM y");
        }

        // Date - short
        df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT, GlobalizationPreferences.DF_NONE);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("dd/MM/yyyy")) {
            errln("FAIL: SHORT date pattern is " + pattern + " Expected: dd/MM/yyyy");
        }

        // Time - full
        df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_FULL);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("HH:mm:ss zzzz")) {
            errln("FAIL: FULL time pattern is " + pattern + " Expected: HH:mm:ss zzzz");
        }

        // Time - long
        df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_LONG);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("HH:mm:ss z")) {
            errln("FAIL: LONG time pattern is " + pattern + " Expected: HH:mm:ss z");
        }

        // Time - medium
        df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_MEDIUM);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("HH:mm:ss")) {
            errln("FAIL: MEDIUM time pattern is " + pattern + " Expected: HH:mm:ss");
        }

        // Time - short
        df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_SHORT);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("HH:mm")) {
            errln("FAIL: SHORT time pattern is " + pattern + " Expected: HH:mm");
        }

        // Date/Time - full
        df = gp.getDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_FULL);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("EEEE, d MMMM y HH:mm:ss zzzz")) {
            errln("FAIL: FULL date/time pattern is " + pattern + " Expected: EEEE, d MMMM y HH:mm:ss zzzz");
        }

        // Invalid style
        boolean illegalArg = false;
        try {
            df = gp.getDateFormat(-1, GlobalizationPreferences.DF_NONE);
        } catch (IllegalArgumentException iae) {
            logln("Illegal date style -1");
            illegalArg = true;
        }
        if (!illegalArg) {
            errln("FAIL: getDateFormat() must throw IllegalArgumentException for dateStyle -1");
        }

        illegalArg = false;
        try {
            df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_NONE);
        } catch (IllegalArgumentException iae) {
            logln("Illegal style - dateStyle:DF_NONE / timeStyle:DF_NONE");
            illegalArg = true;
        }
        if (!illegalArg) {
            errln("FAIL: getDateFormat() must throw IllegalArgumentException for dateStyle:DF_NONE/timeStyle:DF_NONE");
        }

        // Set explicit time zone
        logln("Set timezone - America/Sao_Paulo");
        TimeZone tz = TimeZone.getTimeZone("America/Sao_Paulo");
        gp.setTimeZone(tz);
        df = gp.getDateFormat(GlobalizationPreferences.DF_LONG, GlobalizationPreferences.DF_MEDIUM);
        String tzid = df.getTimeZone().getID();
        if (!tzid.equals("America/Sao_Paulo")) {
            errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
        }

        // Set explicit calendar
        logln("Set calendar - japanese");
        Calendar jcal = new JapaneseCalendar();
        jcal.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
        gp.setCalendar(jcal);
        df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT, GlobalizationPreferences.DF_SHORT);
        Calendar dfCal = df.getCalendar();
        if (!(dfCal instanceof JapaneseCalendar)) {
            errln("FAIL: The DateFormat instance must use Japanese calendar");
        }
        // TimeZone must be still America/Sao_Paulo
        tzid = df.getTimeZone().getID();
        if (!tzid.equals("America/Sao_Paulo")) {
            errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
        }

        // Set explicit DateFormat
        logln("Set explicit date format - full date");
        DateFormat customFD = DateFormat.getDateInstance(new IslamicCalendar(), DateFormat.FULL, new ULocale("ar_SA"));
        customFD.setTimeZone(TimeZone.getTimeZone("Asia/Riyadh"));
        gp.setDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_NONE, customFD);
        df = gp.getDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_NONE);
        dfCal = df.getCalendar();
        if (!(dfCal instanceof IslamicCalendar)) {
            errln("FAIL: The DateFormat instance must use Islamic calendar");
        }
        // TimeZone in the custom DateFormat is overridden by GP's timezone setting
        tzid = df.getTimeZone().getID();
        if (!tzid.equals("America/Sao_Paulo")) {
            errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
        }

        // Freeze
        logln("Freeze this object");
        gp.freeze();
        DateFormat customLD = DateFormat.getDateInstance(new BuddhistCalendar(), DateFormat.LONG, new ULocale("th"));
        customLD.setTimeZone(TimeZone.getTimeZone("Asia/Bangkok"));
        boolean isFrozen = false;
        try {
            gp.setDateFormat(GlobalizationPreferences.DF_LONG, GlobalizationPreferences.DF_NONE, customLD);
        } catch (UnsupportedOperationException uoe) {
View Full Code Here

TOP

Related Classes of com.ibm.icu.util.ULocale$JDKLocaleHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.