use of java.util.Currency in project hibernate-orm by hibernate.
the class MonetaryAmountUserType method nullSafeGet.
public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException {
BigDecimal amt = StandardBasicTypes.BIG_DECIMAL.nullSafeGet(rs, names[0], session);
Currency cur = StandardBasicTypes.CURRENCY.nullSafeGet(rs, names[1], session);
if (amt == null)
return null;
return new MonetaryAmount(amt, cur);
}
use of java.util.Currency in project guava by google.
the class FreshValueGenerator method generateCurrency.
@Generates
private Currency generateCurrency() {
try {
Method method = Currency.class.getMethod("getAvailableCurrencies");
// getAvailableCurrencies() returns Set<Currency>.
@SuppressWarnings("unchecked") Set<Currency> currencies = (Set<Currency>) method.invoke(null);
return pickInstance(currencies, Currency.getInstance(Locale.US));
} catch (NoSuchMethodException notJava7) {
return preJava7FreshCurrency();
} catch (InvocationTargetException cantCallGetAvailableCurrencies) {
return preJava7FreshCurrency();
} catch (IllegalAccessException impossible) {
throw new AssertionError(impossible);
}
}
use of java.util.Currency in project j2objc by google.
the class CurrencyTest method test_getDefaultFractionDigits.
/**
* java.util.Currency#getDefaultFractionDigits()
*/
public void test_getDefaultFractionDigits() {
Currency c1 = Currency.getInstance("TND");
c1.getDefaultFractionDigits();
assertEquals(" Currency.getInstance(\"" + c1 + "\") returned incorrect number of digits. ", 3, c1.getDefaultFractionDigits());
Currency c2 = Currency.getInstance("EUR");
c2.getDefaultFractionDigits();
assertEquals(" Currency.getInstance(\"" + c2 + "\") returned incorrect number of digits. ", 2, c2.getDefaultFractionDigits());
Currency c3 = Currency.getInstance("JPY");
c3.getDefaultFractionDigits();
assertEquals(" Currency.getInstance(\"" + c3 + "\") returned incorrect number of digits. ", 0, c3.getDefaultFractionDigits());
Currency c4 = Currency.getInstance("XXX");
c4.getDefaultFractionDigits();
assertEquals(" Currency.getInstance(\"" + c4 + "\") returned incorrect number of digits. ", -1, c4.getDefaultFractionDigits());
}
use of java.util.Currency in project j2objc by google.
the class CurrencyTest method test_getInstanceLjava_util_Locale.
/**
* java.util.Currency#getInstance(java.util.Locale)
*/
public void test_getInstanceLjava_util_Locale() {
/*
* the behaviour in all these three cases should be the same since this
* method ignores language and variant component of the locale.
*/
Currency c0 = Currency.getInstance("CAD");
Currency c1 = Currency.getInstance(new Locale("en", "CA"));
assertTrue("Currency.getInstance(new Locale(\"en\",\"CA\")) isn't equal to Currency.getInstance(\"CAD\")", c1 == c0);
Currency c2 = Currency.getInstance(new Locale("fr", "CA"));
assertTrue("Currency.getInstance(new Locale(\"fr\",\"CA\")) isn't equal to Currency.getInstance(\"CAD\")", c2 == c0);
Currency c3 = Currency.getInstance(new Locale("", "CA"));
assertTrue("Currency.getInstance(new Locale(\"\",\"CA\")) isn't equal to Currency.getInstance(\"CAD\")", c3 == c0);
c0 = Currency.getInstance("JPY");
c1 = Currency.getInstance(new Locale("ja", "JP"));
assertTrue("Currency.getInstance(new Locale(\"ja\",\"JP\")) isn't equal to Currency.getInstance(\"JPY\")", c1 == c0);
c2 = Currency.getInstance(new Locale("", "JP"));
assertTrue("Currency.getInstance(new Locale(\"\",\"JP\")) isn't equal to Currency.getInstance(\"JPY\")", c2 == c0);
c3 = Currency.getInstance(new Locale("bogus", "JP"));
assertTrue("Currency.getInstance(new Locale(\"bogus\",\"JP\")) isn't equal to Currency.getInstance(\"JPY\")", c3 == c0);
Locale localeGu = new Locale("gu", "IN");
Currency cGu = Currency.getInstance(localeGu);
Locale localeKn = new Locale("kn", "IN");
Currency cKn = Currency.getInstance(localeKn);
assertTrue("Currency.getInstance(Locale_" + localeGu.toString() + "))" + "isn't equal to " + "Currency.getInstance(Locale_" + localeKn.toString() + "))", cGu == cKn);
// some teritories do not have currencies, like Antarctica
Locale loc = new Locale("", "AQ");
try {
Currency curr = Currency.getInstance(loc);
assertNull("Currency.getInstance(new Locale(\"\", \"AQ\")) did not return null", curr);
} catch (IllegalArgumentException e) {
fail("Unexpected IllegalArgumentException " + e);
}
/* These return valid currencies in iOS.
// unsupported/legacy iso3 countries
loc = new Locale("", "ZR");
try {
Currency curr = Currency.getInstance(loc);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
loc = new Locale("", "ZAR");
try {
Currency curr = Currency.getInstance(loc);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
loc = new Locale("", "FX");
try {
Currency curr = Currency.getInstance(loc);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
loc = new Locale("", "FXX");
try {
Currency curr = Currency.getInstance(loc);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}*/
}
use of java.util.Currency in project j2objc by google.
the class CurrencyTest method test_getSymbolLjava_util_Locale.
/**
* java.util.Currency#getSymbol(java.util.Locale)
*/
public void test_getSymbolLjava_util_Locale() {
//Tests was simplified because java specification not
// includes strong requirements for returning symbol.
// on android platform used wrong character for yen
// sign: ¥ instead of ¥
Locale[] desiredLocales = new Locale[] { Locale.JAPAN, Locale.JAPANESE, Locale.FRANCE, Locale.FRENCH, Locale.US, Locale.UK, Locale.CANADA, Locale.CANADA_FRENCH, Locale.ENGLISH, new Locale("ja", "JP"), new Locale("", "JP"), new Locale("fr", "FR"), new Locale("", "FR"), new Locale("en", "US"), new Locale("", "US"), new Locale("es", "US"), new Locale("ar", "US"), new Locale("ja", "US"), new Locale("en", "CA"), new Locale("fr", "CA"), new Locale("", "CA"), new Locale("ar", "CA"), new Locale("ja", "JP"), new Locale("", "JP"), new Locale("ar", "JP"), new Locale("ja", "AE"), new Locale("en", "AE"), new Locale("ar", "AE"), new Locale("da", "DK"), new Locale("", "DK"), new Locale("da", ""), new Locale("ja", ""), new Locale("en", "") };
Set<Locale> availableLocales = new HashSet<Locale>(Arrays.asList(Locale.getAvailableLocales()));
ArrayList<Locale> locales = new ArrayList<Locale>();
for (Locale desiredLocale : desiredLocales) {
if (availableLocales.contains(desiredLocale)) {
locales.add(desiredLocale);
}
}
Locale[] loc1 = locales.toArray(new Locale[locales.size()]);
String[] euro = new String[] { "EUR", "€" };
// ¥ and ¥ are actually the same symbol, just different code points.
// But the RI returns the ¥ and Android returns those with ¥
String[] yen = new String[] { "JPY", "¥", "¥JP", "JP¥", "¥", "¥JP", "JP¥" };
String[] dollar = new String[] { "USD", "$", "US$", "$US", "$ US" };
// BEGIN android-changed
// Starting CLDR 1.7 release, currency symbol for CAD changed to CA$ in some locales such as ja.
String[] cDollar = new String[] { "CA$", "CAD", "$", "Can$", "$CA" };
// END android-changed
Currency currE = Currency.getInstance("EUR");
Currency currJ = Currency.getInstance("JPY");
Currency currUS = Currency.getInstance("USD");
Currency currCA = Currency.getInstance("CAD");
int i, j, k;
boolean flag;
for (k = 0; k < loc1.length; k++) {
Locale.setDefault(loc1[k]);
for (i = 0; i < loc1.length; i++) {
flag = false;
for (j = 0; j < euro.length; j++) {
if (currE.getSymbol(loc1[i]).equals(euro[j])) {
flag = true;
break;
}
}
assertTrue("Default Locale is: " + Locale.getDefault() + ". For locale " + loc1[i] + " the Euro currency returned " + currE.getSymbol(loc1[i]) + ". Expected was one of these: " + Arrays.toString(euro), flag);
}
for (i = 0; i < loc1.length; i++) {
flag = false;
for (j = 0; j < yen.length; j++) {
if (currJ.getSymbol(loc1[i]).equals(yen[j])) {
flag = true;
break;
}
}
assertTrue("Default Locale is: " + Locale.getDefault() + ". For locale " + loc1[i] + " the Yen currency returned " + currJ.getSymbol(loc1[i]) + ". Expected was one of these: " + Arrays.toString(yen), flag);
}
for (i = 0; i < loc1.length; i++) {
flag = false;
for (j = 0; j < dollar.length; j++) {
if (currUS.getSymbol(loc1[i]).equals(dollar[j])) {
flag = true;
break;
}
}
assertTrue("Default Locale is: " + Locale.getDefault() + ". For locale " + loc1[i] + " the Dollar currency returned " + currUS.getSymbol(loc1[i]) + ". Expected was one of these: " + Arrays.toString(dollar), flag);
}
for (i = 0; i < loc1.length; i++) {
flag = false;
for (j = 0; j < cDollar.length; j++) {
if (currCA.getSymbol(loc1[i]).equals(cDollar[j])) {
flag = true;
break;
}
}
assertTrue("Default Locale is: " + Locale.getDefault() + ". For locale " + loc1[i] + " the Canadian Dollar currency returned " + currCA.getSymbol(loc1[i]) + ". Expected was one of these: " + Arrays.toString(cDollar), flag);
}
}
}
Aggregations