本文整理汇总了Java中javax.money.CurrencyQueryBuilder类的典型用法代码示例。如果您正苦于以下问题:Java CurrencyQueryBuilder类的具体用法?Java CurrencyQueryBuilder怎么用?Java CurrencyQueryBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CurrencyQueryBuilder类属于javax.money包,在下文中一共展示了CurrencyQueryBuilder类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCurrency
import javax.money.CurrencyQueryBuilder; //导入依赖的package包/类
/**
* Access a new instance based on the currency code. Currencies are
* available as provided by {@link javax.money.spi.CurrencyProviderSpi} instances registered
* with the {@link javax.money.spi.Bootstrap}.
*
* @param currencyCode the ISO currency code, not {@code null}.
* @param providers the (optional) specification of providers to consider. If not set (empty) the providers
* as defined by #getDefaultRoundingProviderChain() should be used.
* @return the corresponding {@link javax.money.CurrencyUnit} instance.
* @throws javax.money.UnknownCurrencyException if no such currency exists.
*/
public CurrencyUnit getCurrency(String currencyCode, String... providers) {
Objects.requireNonNull(currencyCode, "Currency Code may not be null");
Collection<CurrencyUnit> found =
getCurrencies(CurrencyQueryBuilder.of().setCurrencyCodes(currencyCode).setProviderNames(providers).build());
if (found.isEmpty()) {
throw new UnknownCurrencyException(currencyCode);
}
if (found.size() > 1) {
throw new MonetaryException("Ambiguous CurrencyUnit for code: " + currencyCode + ": " + found);
}
return found.iterator().next();
}
示例2: main
import javax.money.CurrencyQueryBuilder; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
ConsoleUtils.printDetails(Monetary.getCurrency("CHF"));
Monetary.getCurrencies(CurrencyQueryBuilder.of().setProviderNames("ConfigurableCurrencyUnitProvider").build()).forEach(
ConsoleUtils::printDetails
);
CurrencyUnitBuilder.of("GeeCon", "GeeCon-Conference").build(true);
Monetary.getCurrencies(CurrencyQueryBuilder.of().setProviderNames("ConfigurableCurrencyUnitProvider").build()).forEach(
ConsoleUtils::printDetails
);
}
示例3: main
import javax.money.CurrencyQueryBuilder; //导入依赖的package包/类
public static void main(String[] args) {
ConsoleUtils.printDetails(
CurrencyUnitBuilder.of("GeeCoin", "BuildingCurrenciesExample").setCurrencyCode("GCC").setDefaultFractionDigits(2).build());
Monetary.getCurrencies(CurrencyQueryBuilder.of().setProviderNames("ConfigurableCurrencyUnitProvider").build()).forEach(
ConsoleUtils::printDetails
);
ConsoleUtils.printDetails(
CurrencyUnitBuilder.of("GeeCoin", "BuildingCurrenciesExample").setCurrencyCode("GCC").setDefaultFractionDigits(2).build(true));
}
示例4: getNamespaceQuery
import javax.money.CurrencyQueryBuilder; //导入依赖的package包/类
@Override
public CurrencyQuery getNamespaceQuery(String targetNamespace){
return CurrencyQueryBuilder.of().set(CurrencyMappingQuerySelector.NAMESPACE)
.set("targetNamespace", targetNamespace).build();
}
示例5: getCurrencies
import javax.money.CurrencyQueryBuilder; //导入依赖的package包/类
/**
* Provide access to all currently known currencies.
*
* @param locale the target {@link java.util.Locale}, typically representing an ISO country,
* not {@code null}.
* @param providers the (optional) specification of providers to consider. If not set (empty) the providers
* as defined by #getDefaultRoundingProviderChain() should be used.
* @return a collection of all known currencies, never null.
*/
public Set<CurrencyUnit> getCurrencies(Locale locale, String... providers) {
return getCurrencies(CurrencyQueryBuilder.of().setCountries(locale).setProviderNames(providers).build());
}
示例6: isCurrencyAvailable
import javax.money.CurrencyQueryBuilder; //导入依赖的package包/类
/**
* Allows to check if a {@link javax.money.CurrencyUnit} instance is defined, i.e.
* accessible from {@link BaseMonetaryCurrenciesSingletonSpi#getCurrency(String, String...)}.
*
* @param code the currency code, not {@code null}.
* @param providers the (optional) specification of providers to consider. If not set (empty) the providers
* as defined by #getDefaultRoundingProviderChain() should be used.
* @return {@code true} if {@link BaseMonetaryCurrenciesSingletonSpi#getCurrency(String, String...)}
* would return a result for the given code.
*/
public boolean isCurrencyAvailable(String code, String... providers) {
return !getCurrencies(CurrencyQueryBuilder.of().setCurrencyCodes(code).setProviderNames(providers).build())
.isEmpty();
}
示例7: getMappingQuery
import javax.money.CurrencyQueryBuilder; //导入依赖的package包/类
/**
* This method maps the given {@link CurrencyUnit} to another
* {@link CurrencyUnit} with the given target namespace.
*
* @param currencyUnit The source unit, never {@code null}.
* @param targetNamespace the target namespace, never {@code null}.
* @return The mapped {@link CurrencyUnit}, or {@code null}.
*/
@Override
public CurrencyQuery getMappingQuery(CurrencyUnit currencyUnit, String targetNamespace){
return CurrencyQueryBuilder.of().set(CurrencyMappingQuerySelector.MAPPING).set(currencyUnit, CurrencyUnit.class)
.set("targetNamespace", targetNamespace).build();
}