Examples of GlobalizationPreferences


Examples of com.ibm.icu.util.GlobalizationPreferences

        }

    }

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

        NumberFormat nf;
        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();
        try {
            gp.setNumberFormat(GlobalizationPreferences.NF_NUMBER, customNum1);
        } catch (UnsupportedOperationException uoe) {
            logln("setNumberFormat is blocked");
            isFrozen = true;
        }
        if (!isFrozen) {
            errln("FAIL: setNumberFormat must be blocked after frozen");
        }

        // Create a modifiable clone
        GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();

        // Number type format's locale is still he_IL
        nf = gp1.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
        if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("he_IL")) {
            errln("FAIL: The NumberFormat instance must use locale he_IL");
        }

        logln("Set custom number format using locale hi_IN");
        gp1.setNumberFormat(GlobalizationPreferences.NF_NUMBER, customNum1);
        nf = gp1.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
        if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("hi_IN")) {
            errln("FAIL: The NumberFormat instance must use locale hi_IN");
        }
    }
View Full Code Here

Examples of com.ibm.icu.util.GlobalizationPreferences

    /*
     * JB#5380 GlobalizationPreferences#getCalendar() should return a Calendar object
     * initialized with the current time
     */
    public void TestJB5380() {
        GlobalizationPreferences gp = new GlobalizationPreferences();
        GregorianCalendar gcal = new GregorianCalendar();

        // set way old date
        gcal.set(Calendar.YEAR, 1950);

        // set calendar to GP
        gp.setCalendar(gcal);

        Calendar cal = gp.getCalendar();
        // Calendar instance returned from GP should be initialized
        // by the current time
        long timeDiff = System.currentTimeMillis() - cal.getTimeInMillis();
        if (Math.abs(timeDiff) > 1000) {
            // if difference is more than 1 second..
View Full Code Here

Examples of com.ibm.icu.util.GlobalizationPreferences

   * @param locales
   * @return the sorted list of ULocale instances
   */
  public static List<ULocale> getProcessedLocaleList(String[] locales){
    if (locales == null) return getDefaultLocaleList();
    GlobalizationPreferences prefs = new GlobalizationPreferences();
   
    ArrayList<ULocale> ulocales = new ArrayList<ULocale>();
    for (String locale:locales){
      if (locale != null){
        try {
          ULocale ulocale = ULocale.forLanguageTag(locale);
          if (!ulocale.getLanguage().equals(""))
            ulocales.add(ulocale);
        } catch (Exception e) {
          // There can be intermittent problems with the internal
          // functioning of the ULocale class with some
          // language tags; best to just log these and continue
          _logger.error("icu4j:ULocale.forLanguageTag("+locale+") threw Exception:",e);
        }
      }
    } 
    if (ulocales.isEmpty()) return getDefaultLocaleList();
    prefs.setLocales(ulocales.toArray(new ULocale[ulocales.size()]));
    return prefs.getLocales();
  }
View Full Code Here

Examples of com.ibm.icu.util.GlobalizationPreferences

  /**
   * Gets the default locales list
   * @return a list of ULocale instances for the default locale
   */
  protected static List<ULocale> getDefaultLocaleList(){
    GlobalizationPreferences prefs = new GlobalizationPreferences();
    return prefs.getLocales();
  }
View Full Code Here

Examples of com.ibm.icu.util.GlobalizationPreferences

   * @return
   */
  @SuppressWarnings("unchecked")
  public static List<ULocale> getProcessedLocaleList(String[] locales){
    if (locales == null) return getDefaultLocaleList();
    GlobalizationPreferences prefs = new GlobalizationPreferences();
   
    ArrayList<ULocale> ulocales = new ArrayList<ULocale>();
    for (String locale:locales){
      if (locale != null){
        try {
          ULocale ulocale = ULocale.forLanguageTag(locale);
          if (!ulocale.getLanguage().equals(""))
            ulocales.add(ulocale);
        } catch (Exception e) {
          // There can be intermittent problems with the internal
          // functioning of the ULocale class with some
          // language tags; best to just log these and continue
          _logger.error("icu4j:ULocale.forLanguageTag("+locale+") threw Exception:",e);
        }
      }
    } 
    if (ulocales.isEmpty()) return getDefaultLocaleList();
    prefs.setLocales(ulocales.toArray(new ULocale[ulocales.size()]));
    return prefs.getLocales();
  }
View Full Code Here

Examples of com.ibm.icu.util.GlobalizationPreferences

   * Gets the default locales list
   * @return
   */
  @SuppressWarnings("unchecked")
  protected static List<ULocale> getDefaultLocaleList(){
    GlobalizationPreferences prefs = new GlobalizationPreferences();
    return prefs.getLocales();
  }
View Full Code Here

Examples of com.ibm.icu.util.GlobalizationPreferences

     * @return
     */
    public static List<ULocale> getProcessedLocaleList(String[] locales) {
        if (locales == null)
            return getDefaultLocaleList();
        GlobalizationPreferences prefs = new GlobalizationPreferences();

        ArrayList<ULocale> ulocales = new ArrayList<ULocale>();
        for (String locale : locales) {
            if (locale != null) {
                try {
                    ULocale ulocale = ULocale.forLanguageTag(locale);
                    if (!ulocale.getLanguage().equals(""))
                        ulocales.add(ulocale);
                } catch (Exception e) {
                    // There can be intermittent problems with the internal
                    // functioning of the ULocale class with some
                    // language tags; best to just log these and continue
                    _logger.error("icu4j:ULocale.forLanguageTag(" + locale + ") threw Exception:", e);
                }
            }
        }
        if (ulocales.isEmpty())
            return getDefaultLocaleList();
        prefs.setLocales(ulocales.toArray(new ULocale[ulocales.size()]));
        return prefs.getLocales();
    }
View Full Code Here

Examples of com.ibm.icu.util.GlobalizationPreferences

     * Gets the default locales list
     *
     * @return
     */
    protected static List<ULocale> getDefaultLocaleList() {
        GlobalizationPreferences prefs = new GlobalizationPreferences();
        return prefs.getLocales();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.