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();