本文整理了Java中java.util.Currency.getAvailableCurrencies()
方法的一些代码示例,展示了Currency.getAvailableCurrencies()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Currency.getAvailableCurrencies()
方法的具体详情如下:
包路径:java.util.Currency
类名称:Currency
方法名:getAvailableCurrencies
[英]Returns a set of all known currencies.
[中]返回所有已知货币的集合。
代码示例来源:origin: stackoverflow.com
public static Currency getCurrencyInstance(int numericCode) {
Set<Currency> currencies = Currency.getAvailableCurrencies();
for (Currency currency : currencies) {
if (currency.getNumericCode() == numericCode) {
return currency;
}
}
throw new IllegalArgumentException("Currency with numeric code " + numericCode + " not found");
}
代码示例来源:origin: org.javamoney.moneta/moneta-core
private List<CurrencyUnit> getCurrencyUnits(int numCode) {
List<CurrencyUnit> result = new ArrayList<>();
for(Currency currency: Currency.getAvailableCurrencies()){
if(currency.getNumericCode()==numCode){
result.add(CACHED.get(currency.getCurrencyCode()));
}
}
return result;
}
代码示例来源:origin: stackoverflow.com
public static Currency getCurrencyByCode(int code) {
for(Currency currency : Currency.getAvailableCurrencies()) {
if(currency.getNumericCode() == code) {
return currency;
}
}
throw new IllegalArgumentException("Unkown currency code: " + code);
}
代码示例来源:origin: stackoverflow.com
public static Currency getByCode(int code) {
for(Currency c : Currency.getAvailableCurrencies()) {
if(c.getNumericCode() == code) {
return c;
}
}
throw new IllegalArgumentException("Unkown currency code: " + code);
}
代码示例来源:origin: zavtech/morpheus-core
/**
* Constructor
*/
public OfCurrency() {
super(Currency.class);
this.currencies = Currency.getAvailableCurrencies().stream().toArray(Currency[]::new);
this.codeMap = new TObjectIntHashMap<>(currencies.length, 0.5f, -1);
Arrays.sort(currencies, (c1, c2) -> c1.getCurrencyCode().compareTo(c2.getCurrencyCode()));
for (int i = 0; i< currencies.length; ++i) {
this.codeMap.put(currencies[i], i);
}
}
代码示例来源:origin: org.javamoney.moneta/moneta-core
private static Map<String, CurrencyUnit> loadCurrencies() {
Set<Currency> availableCurrencies = Currency.getAvailableCurrencies();
Map<String, CurrencyUnit> result = new HashMap<>(availableCurrencies.size());
for (Currency jdkCurrency : availableCurrencies) {
CurrencyUnit cu = new JDKCurrencyAdapter(jdkCurrency);
result.put(cu.getCurrencyCode(), cu);
}
return Collections.unmodifiableMap(result);
}
代码示例来源:origin: stackoverflow.com
String userInput = "250.00 SEK";
final Set<Currency> availableCurrencies = Currency.getAvailableCurrencies();
for (Currency availableCurrency : availableCurrencies) {
final String currencyCode = availableCurrency.getCurrencyCode();
final String displayName = availableCurrency.getDisplayName();
if (userInput.contains(currencyCode)){
System.out.println("Currency is " + availableCurrency.getDisplayName());
}
}
代码示例来源:origin: stackoverflow.com
Set<Currency> avail = Currency.getAvailableCurrencies();
for (Currency next : avail) {
System.out.println("----------------------------------------");
System.out.println("displayName="+next.getDisplayName());
System.out.println("currencyCode="+next.getCurrencyCode());
System.out.println("numericCode="+next.getNumericCode());
System.out.println("symbol="+next.getSymbol());
System.out.println("toString="+next.toString());
System.out.println("----------------------------------------");
}
代码示例来源:origin: stackoverflow.com
String currency = €;
String currencyCode = "";
for (Currency c : Currency.getAvailableCurrencies()) {
if (c.getSymbol().equals(currency)) {
currencyCode = c.toString();
}
}
代码示例来源:origin: stackoverflow.com
String userInput = "250.00 SEK";
final Set<Currency> availableCurrencies = Currency.getAvailableCurrencies();
for (Currency availableCurrency : availableCurrencies) {
final String strCode = availableCurrency.getCurrencyCode();
final String currencyCode = strCode;
if (userInput.contains(currencyCode)){
for (Locale locale : NumberFormat.getAvailableLocales()) {
String code = NumberFormat.getCurrencyInstance(locale).getCurrency().getCurrencyCode();
if (strCode.equals(code)) {
System.out.println(locale.getDisplayCountry());;
}
}
}
}
代码示例来源:origin: com.tcdng.unify/unify-core
@Override
protected List<ListData> create(Locale locale, Object... params) throws Exception {
List<ListData> list = new ArrayList<ListData>();
for (Currency currency : Currency.getAvailableCurrencies()) {
list.add(new ListData(currency.getCurrencyCode(), currency.getDisplayName(locale)));
}
DataUtils.sort(list, ListData.class, "listDescription", true);
return list;
}
代码示例来源:origin: jpos/jPOS
private static void addJavaCurrencies()
{
List<java.util.Currency> currencies = java.util.Currency.getAvailableCurrencies()
.stream()
.sorted(Comparator.comparing(java.util.Currency::getCurrencyCode))
.collect(Collectors.toList());
for (java.util.Currency sc : currencies)
{
try
{
addCurrency(sc.getCurrencyCode().toUpperCase(),
ISOUtil.zeropad(Integer.toString(sc.getNumericCode()), 3),
sc.getDefaultFractionDigits());
}
catch (ISOException ignored)
{
}
}
}
代码示例来源:origin: stackoverflow.com
Set<Currency> currencies = Currency.getAvailableCurrencies();
for (Currency currency: currencies) {
System.out.printf("%s\t%s\t%s\n",currency.getDisplayName(), currency.getSymbol(), currency.toString());
// your code to check whether the symbol is not empty here
// add it to your String array or just directly use the
// CharSequences arrays for entries and values here.
}
代码示例来源:origin: org.javamoney/javamoney-tck
/**
* Ensure all ISO 3-letters codes as defined by the JDK are also
* available from Monetary.
*/
@SpecAssertion(section = "4.2.1", id = "421-A3")
@Test(description = "4.2.1 Test currencies provided have correct ISO 3-letter currency codes.")
public void testEnforce3LetterCode4ISO() {
for (Currency currency : Currency.getAvailableCurrencies()) {
CurrencyUnit unit = Monetary.getCurrency(currency.getCurrencyCode());
AssertJUnit.assertNotNull(unit);
AssertJUnit.assertEquals(currency.getCurrencyCode(), unit.getCurrencyCode());
}
}
代码示例来源:origin: org.javamoney/javamoney-tck
/**
* Test if Monetary provides all ISO related entries,
* similar to the JDK.
*/
@Test(description = "4.2.7 Test if Monetary provides all ISO related entries similar to " +
"java.util.Currency.")
@SpecAssertion(section = "4.2.7", id = "427-A1")
public void testAllISOCurrenciesAvailable() {
for (Currency currency : Currency.getAvailableCurrencies()) {
AssertJUnit.assertTrue(
"Section 4.2.7: Currency not available [Monetary#isCurrencyAvailable(String)] for JDK " +
"currency code: " +
currency.getCurrencyCode(),
Monetary.isCurrencyAvailable(currency.getCurrencyCode()));
AssertJUnit.assertNotNull(
"Section 4.2.7: Currency null [Monetary#igetCurrency(String)] for JDK currency code: " +
currency.getCurrencyCode(), Monetary.getCurrency(currency.getCurrencyCode()));
}
}
代码示例来源:origin: org.javamoney/javamoney-tck
/**
* Tests that currencies returned for same ISO currency code are
* equal, ensure when listing all available currencies, that the
* code
* is unique.
*/
@SpecAssertion(section = "4.2.1", id = "421-A2")
@Test(description = "4.2.1 Test currencies provided equal at least currencies from java.util.Currency.")
public void testEqualISOCurrencies() {
for (Currency currency : Currency.getAvailableCurrencies()) {
CurrencyUnit unit = Monetary.getCurrency(currency.getCurrencyCode());
AssertJUnit.assertNotNull(unit);
CurrencyUnit unit2 = Monetary.getCurrency(currency.getCurrencyCode());
AssertJUnit.assertNotNull(unit2);
AssertJUnit.assertEquals(unit, unit2);
}
}
代码示例来源:origin: org.javamoney/javamoney-tck
/**
* For each MonetaryAmount Factory: Bad Case: Create zero amounts
* from a factory with an invalid currency.
*/
@Test(description = "4.2.6 Bad case: For each MonetaryAmount Factory: Create zero amounts" +
" from a factory with an invalid currency.")
@SpecAssertion(section = "4.2.6", id = "426-B3")
public void testMonetaryAmountFactoryCreateAmountsWithInvalidCurrency() {
for (Class type : Monetary.getAmountTypes()) {
if (type.equals(TestAmount.class)) {
continue;
}
for (Currency cur : Currency.getAvailableCurrencies()) {
Monetary.getCurrency(cur.getCurrencyCode());
MonetaryAmountFactory<?> f = Monetary.getAmountFactory(type);
try {
f.setCurrency("shjgssgsjgsj");
AssertJUnit
.fail("Section 4.2.6: Factory should throw UnknownCurrencyException for invalid currency," +
" type was " +
type.getName());
} catch (UnknownCurrencyException e) {
// OK
}
}
}
}
代码示例来源:origin: org.javamoney/javamoney-tck
/**
* For each MonetaryAmount implementation: Ensure getCurrencyCode
* returns correct results.
*/
@SpecAssertion(section = "4.2.2", id = "422-A1")
@Test(description = "4.2.2 Ensure amount can be created with all default currencies.")
public void testCurrencyCode() {
for (Class type : Monetary.getAmountTypes()) {
for (Currency jdkCur : Currency.getAvailableCurrencies()) {
MonetaryAmount amount =
Monetary.getDefaultAmountFactory().setCurrency(jdkCur.getCurrencyCode()).setNumber(10.15)
.create();
AssertJUnit.assertNotNull(
"Section 4.2.2: Amount factory returned null for new amount type: " + type.getName(), amount);
AssertJUnit.assertNotNull(
"Section 4.2.2: Amount factory returned new amount with null currency, type: " + type.getName(),
amount.getCurrency());
AssertJUnit.assertEquals(
"Section 4.2.2: Amount factory returned new amount with invalid currency, type: " +
type.getName(), jdkCur.getCurrencyCode(), amount.getCurrency().getCurrencyCode());
}
}
}
代码示例来源:origin: org.javamoney/javamoney-tck
/**
* Test that JDK currencies returned match the values of corresponding JDK Currency (code, numeric code,
* default fraction digits).
*/
@SpecAssertion(section = "4.2.1", id = "421-A4")
@Test(description = "4.2.1 Test currencies provided have correct default fraction digits and numeric code.")
public void testISOCodes() {
for (Currency currency : Currency.getAvailableCurrencies()) {
CurrencyUnit unit = Monetary.getCurrency(currency.getCurrencyCode());
AssertJUnit.assertEquals(currency.getCurrencyCode(), unit.getCurrencyCode());
AssertJUnit.assertEquals(currency.getDefaultFractionDigits(), unit.getDefaultFractionDigits());
AssertJUnit.assertEquals(currency.getNumericCode(), unit.getNumericCode());
}
}
代码示例来源:origin: jpos/jPOS
@Test
public void testAllISOCurrenciesIncluded() {
Set<java.util.Currency> currencies = java.util.Currency.getAvailableCurrencies();
StringBuilder msg = new StringBuilder();
for (java.util.Currency sc : currencies) {
try {
if (sc.getDefaultFractionDigits() < 0) continue; // Skip pseudo currencies
int currencyCode = sc.getNumericCode();
Currency currencyByCode = ISOCurrency.getCurrency(currencyCode);
assertEquals("jPOS currency does not match decimals", sc.getDefaultFractionDigits(), currencyByCode.getDecimals());
} catch (Throwable ignored) {
msg.append(sc.getCurrencyCode().toUpperCase() + "=" +
ISOUtil.zeropad(sc.getNumericCode(), 3) + " " + sc.getDefaultFractionDigits() +
" //" + sc.getDisplayName() + ":" + ignored.getMessage() + "\n");
}
}
assertEquals(msg.toString(), msg.length(), 0);
}
内容来源于网络,如有侵权,请联系作者删除!