Package com.ibm.icu.util

Examples of com.ibm.icu.util.ULocale


        String numStr;
        double num = 123456.789;

        // Set unsupported locale with supported territory ang_KR
        logln("Set locale - ang_KR");
        gp.setLocale(new ULocale("ang_KR"));
        nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
        numStr = nf.format(num);
        if (!numStr.equals("\u20a9\u00a0123,457")) {
            errln("FAIL: Number string is " + numStr + " Expected: \u20a9\u00a0123,457");
        }
       
        // Set locale - de_DE
        logln("Set locale - de_DE");
        gp.setLocale(new ULocale("de_DE"));

        // NF_NUMBER
        logln("NUMBER type");
        nf = gp.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
        numStr = nf.format(num);
        if (!numStr.equals("123.456,789")) {
            errln("FAIL: Number string is " + numStr + " Expected: 123.456,789");
        }

        // NF_CURRENCY
        logln("CURRENCY type");
        nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
        numStr = nf.format(num);
        if (!numStr.equals("123.456,79\u00a0\u20AC")) {
            errln("FAIL: Number string is " + numStr + " Expected: 123.456,79\u00a0\u20AC");
        }

        // NF_PERCENT
        logln("PERCENT type");
        nf = gp.getNumberFormat(GlobalizationPreferences.NF_PERCENT);
        numStr = nf.format(num);
        if (!numStr.equals("12.345.679\u00a0%")) {
            errln("FAIL: Number string is " + numStr + " Expected: 12.345.679\u00a0%");
        }

        // NF_SCIENTIFIC
        logln("SCIENTIFIC type");
        nf = gp.getNumberFormat(GlobalizationPreferences.NF_SCIENTIFIC);
        numStr = nf.format(num);
        if (!numStr.equals("1,23456789E5")) {
            errln("FAIL: Number string is " + numStr + " Expected: 1,23456789E5");
        }

        // NF_INTEGER
        logln("INTEGER type");
        nf = gp.getNumberFormat(GlobalizationPreferences.NF_INTEGER);
        numStr = nf.format(num);
        if (!numStr.equals("123.457")) {
            errln("FAIL: Number string is " + numStr + " Expected: 123.457");
        }

        // Invalid number type
        logln("INVALID type");
        boolean illegalArg = false;
        try {
            nf = gp.getNumberFormat(100);
        } catch (IllegalArgumentException iae) {
            logln("Illegal number format type 100");
            illegalArg = true;
        }
        if (!illegalArg) {
            errln("FAIL: getNumberFormat must throw IllegalArgumentException for type 100");
        }
        illegalArg = false;
        try {
            nf = gp.getNumberFormat(-1);
        } catch (IllegalArgumentException iae) {
            logln("Illegal number format type -1");
            illegalArg = true;
        }
        if (!illegalArg) {
            errln("FAIL: getNumberFormat must throw IllegalArgumentException for type -1");
        }
       
        // Set explicit territory
        logln("Set territory - US");
        gp.setTerritory("US");
        nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
        numStr = nf.format(num);
        if (!numStr.equals("123.456,79\u00a0$")) {
            errln("FAIL: Number string is " + numStr + " Expected: 123.456,79\u00a0$");
        }

        // Set explicit currency
        logln("Set currency - GBP");
        gp.setCurrency(Currency.getInstance("GBP"));
        nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
        numStr = nf.format(num);
        if (!numStr.equals("123.456,79\u00a0\u00A3")) {
            errln("FAIL: Number string is " + numStr + " Expected: 123.456,79\u00a0\u00A3");
        }

        // Set exliplicit NumberFormat
        logln("Set explicit NumberFormat objects");
        NumberFormat customNum = NumberFormat.getNumberInstance(new ULocale("he_IL"));
        gp.setNumberFormat(GlobalizationPreferences.NF_NUMBER, customNum);
        NumberFormat customCur = NumberFormat.getCurrencyInstance(new ULocale("zh_CN"));
        gp.setNumberFormat(GlobalizationPreferences.NF_CURRENCY, customCur);
        NumberFormat customPct = NumberFormat.getPercentInstance(new ULocale("el_GR"));
        gp.setNumberFormat(GlobalizationPreferences.NF_PERCENT, customPct);
        NumberFormat customSci = NumberFormat.getScientificInstance(new ULocale("ru_RU"));
        gp.setNumberFormat(GlobalizationPreferences.NF_SCIENTIFIC, customSci);
        NumberFormat customInt = NumberFormat.getIntegerInstance(new ULocale("pt_PT"));
        gp.setNumberFormat(GlobalizationPreferences.NF_INTEGER, customInt);

       
        nf = gp.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
        if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("he_IL")) {
            errln("FAIL: The NumberFormat instance must use locale he_IL");
        }
        nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
        if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("zh_CN")) {
            errln("FAIL: The NumberFormat instance must use locale zh_CN");
        }
        nf = gp.getNumberFormat(GlobalizationPreferences.NF_PERCENT);
        if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("el_GR")) {
            errln("FAIL: The NumberFormat instance must use locale el_GR");
        }
        nf = gp.getNumberFormat(GlobalizationPreferences.NF_SCIENTIFIC);
        if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("ru_RU")) {
            errln("FAIL: The NumberFormat instance must use locale ru_RU");
        }
        nf = gp.getNumberFormat(GlobalizationPreferences.NF_INTEGER);
        if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("pt_PT")) {
            errln("FAIL: The NumberFormat instance must use locale pt_PT");
        }

        NumberFormat customNum1 = NumberFormat.getNumberInstance(new ULocale("hi_IN"));

        // Freeze
        logln("Freeze this object");
        boolean isFrozen = false;
        gp.freeze();
View Full Code Here


            String str = currentCase.getString("str");
           
            Date fromDate = null;
            boolean useDate = false;
           
            ULocale loc = new ULocale(locale);
            String pattern = null;
//            boolean usePattern = false;
            DateFormat format = null;
            DateTimeStyleSet styleSet;
            CalendarFieldsSet fromSet = null;
View Full Code Here

               
        sampleName = "ll_CC_VVVV";
        longULocaleName = "ll_Ssss_CC_VVVV@collation=phonebook;key=value";
        longULocaleBasename = longULocaleName.substring(0, longULocaleName.indexOf('@'));
        nonNormalizedName = "LL_ssss_cc_VVVV@ Key = value ; Collation = phonebook ; ";
        longULocale = new ULocale(longULocaleName);
        sampleLocale = new ULocale(sampleName).toLocale();
    }
View Full Code Here

       
    /*
     * Test method for 'com.ibm.icu.x.util.ULocale.hashCode()'
     */
    public void testHashCode() {
        ULocale obj = ULocale.GERMANY;
        ULocale eq = new ULocale("de_DE");
        ULocale neq = new ULocale("de_DE_FRENCH");
               
        ICUTestCase.testEHCS(obj, eq, neq);
    }
View Full Code Here

    /*
     * Test method for 'com.ibm.icu.x.util.ULocale.ULocale(String)'
     */
    public void testULocaleString() {
        assertEquals(ULocale.GERMAN, new ULocale("de"));
    }
View Full Code Here

    /*
     * Test method for 'com.ibm.icu.x.util.ULocale.ULocale(String, String)'
     */
    public void testULocaleStringString() {
        assertEquals(ULocale.GERMANY, new ULocale("de", "DE"));
    }
View Full Code Here

    /*
     * Test method for 'com.ibm.icu.x.util.ULocale.ULocale(String, String, String)'
     */
    public void testULocaleStringStringString() {
        assertEquals(sampleLocale, new ULocale("ll", "cc", "VVVV").toLocale());
    }
View Full Code Here

    /*
     * Test method for 'com.ibm.icu.x.util.ULocale.createCanonical(String)'
     */
    public void testCreateCanonical() {
        ULocale result = ULocale.createCanonical("de__PHONEBOOK");
        assertEquals(new ULocale("de@collation=phonebook"), result);
    }
View Full Code Here

    /*
     * Test method for 'com.ibm.icu.x.util.ULocale.toLocale()'
     */
    public void testToLocale() {
        assertEquals(sampleLocale, new ULocale("ll", "cc", "VVVV").toLocale());
    }
View Full Code Here

    /*
     * Test method for 'com.ibm.icu.x.util.ULocale.setDefault(ULocale)'
     */
    public void testSetDefault() {
        Locale oldLocale = Locale.getDefault();
        ULocale oldULocale = ULocale.getDefault();
        try {
            ULocale.setDefault(longULocale);
            ICUTestCase.assertNotEqual(Locale.getDefault(), oldLocale);
            ICUTestCase.assertNotEqual(ULocale.getDefault(), oldULocale);
            assertEquals(longULocale, ULocale.getDefault());
View Full Code Here

TOP

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

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.