java.util.Currency.getInstance()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中java.util.Currency.getInstance()方法的一些代码示例,展示了Currency.getInstance()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Currency.getInstance()方法的具体详情如下:
包路径:java.util.Currency
类名称:Currency
方法名:getInstance

Currency.getInstance介绍

[英]Returns the Currency instance for the given ISO 4217 currency code.
[中]返回给定ISO 4217货币代码的货币实例。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public Currency convert(String source) {
  return Currency.getInstance(source);
}

代码示例来源:origin: org.springframework/spring-core

@Override
public Currency convert(String source) {
  return Currency.getInstance(source);
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public Currency fromString(String string) {
  return Currency.getInstance( string );
}

代码示例来源:origin: spring-projects/spring-data-examples

@Override
  public Currency convert(String source) {
    return Currency.getInstance(source);
  }
}

代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl

@Override
  protected Currency _deserialize(String value, DeserializationContext ctxt)
    throws IllegalArgumentException
  {
    // will throw IAE if unknown:
    return Currency.getInstance(value);
  }
}

代码示例来源:origin: aws/aws-sdk-java

@Override
  public final Currency convert(final String o) {
    return Currency.getInstance(o);
  }
};

代码示例来源:origin: google/guava

private Currency preJava7FreshCurrency() {
 for (Set<Locale> uselessLocales = Sets.newHashSet(); ; ) {
  Locale locale = generateLocale();
  if (uselessLocales.contains(locale)) { // exhausted all locales
   return Currency.getInstance(Locale.US);
  }
  try {
   return Currency.getInstance(locale);
  } catch (IllegalArgumentException e) {
   uselessLocales.add(locale);
  }
 }
}

代码示例来源:origin: spring-projects/spring-framework

private Currency determineCurrency(String text, Locale locale) {
    try {
      if (text.length() < 3) {
        // Could not possibly contain a currency code ->
        // try with locale and likely let it fail on parse.
        return Currency.getInstance(locale);
      }
      else if (this.pattern.startsWith(CURRENCY_CODE_PATTERN)) {
        return Currency.getInstance(text.substring(0, 3));
      }
      else if (this.pattern.endsWith(CURRENCY_CODE_PATTERN)) {
        return Currency.getInstance(text.substring(text.length() - 3));
      }
      else {
        // A pattern without a currency code...
        return Currency.getInstance(locale);
      }
    }
    catch (IllegalArgumentException ex) {
      throw new IllegalArgumentException("Cannot determine currency for number value [" + text + "]", ex);
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void setAsText(String text) throws IllegalArgumentException {
  setValue(Currency.getInstance(text));
}

代码示例来源:origin: looly/hutool

@Override
protected Currency convertInternal(Object value) {
  return Currency.getInstance(value.toString());
}

代码示例来源:origin: google/guava

@Generates
private Currency generateCurrency() {
 try {
  Method method = Currency.class.getMethod("getAvailableCurrencies");
  @SuppressWarnings("unchecked") // getAvailableCurrencies() returns Set<Currency>.
  Set<Currency> currencies = (Set<Currency>) method.invoke(null);
  return pickInstance(currencies, Currency.getInstance(Locale.US));
 } catch (NoSuchMethodException | InvocationTargetException notJava7) {
  return preJava7FreshCurrency();
 } catch (IllegalAccessException impossible) {
  throw new AssertionError(impossible);
 }
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
  public <X> Currency wrap(X value, WrapperOptions options) {
    if ( value == null ) {
      return null;
    }
    if ( String.class.isInstance( value ) ) {
      return Currency.getInstance( (String) value );
    }
    throw unknownWrap( value.getClass() );
  }
}

代码示例来源:origin: org.springframework/spring-beans

@Override
public void setAsText(String text) throws IllegalArgumentException {
  setValue(Currency.getInstance(text));
}

代码示例来源:origin: requery/requery

@Override
  public Map<Currency, String> getTestCases() {
    Map<Currency, String> testCases = new HashMap<>();
//        for (Currency currency : Currency.getAvailableCurrencies()) {
//            testCases.put(currency, currency.getCurrencyCode());
//        }
    testCases.put(Currency.getInstance("EUR"), "EUR");
    testCases.put(Currency.getInstance("HKD"), "HKD");
    testCases.put(Currency.getInstance("USD"), "USD");
    testCases.put(null, null);
    return testCases;
  }

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testCurrencyType() {
  final Currency original = Currency.getInstance( Locale.US );
  final Currency copy = Currency.getInstance( Locale.US );
  final Currency different = Currency.getInstance( Locale.UK );
  runBasicTests( CurrencyType.INSTANCE, original, copy, different );
}

代码示例来源:origin: hibernate/hibernate-orm

public static MonetaryAmount fromString(String amount, String currencyCode) {
  return new MonetaryAmount(new BigDecimal(amount),
               Currency.getInstance(currencyCode));
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public String print(MonetaryAmount object, Locale locale) {
  CurrencyStyleFormatter formatter = new CurrencyStyleFormatter();
  formatter.setCurrency(Currency.getInstance(object.getCurrency().getCurrencyCode()));
  formatter.setPattern(this.pattern);
  return formatter.print(object.getNumber(), locale);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testStringToCurrency() {
  assertEquals(Currency.getInstance("EUR"), conversionService.convert("EUR", Currency.class));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testCurrencyToString() {
  assertEquals("USD", conversionService.convert(Currency.getInstance("USD"), String.class));
}

代码示例来源:origin: org.springframework/spring-context

@Override
public String print(MonetaryAmount object, Locale locale) {
  CurrencyStyleFormatter formatter = new CurrencyStyleFormatter();
  formatter.setCurrency(Currency.getInstance(object.getCurrency().getCurrencyCode()));
  formatter.setPattern(this.pattern);
  return formatter.print(object.getNumber(), locale);
}

相关文章