本文整理汇总了Java中org.javamoney.moneta.spi.MonetaryConfig类的典型用法代码示例。如果您正苦于以下问题:Java MonetaryConfig类的具体用法?Java MonetaryConfig怎么用?Java MonetaryConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MonetaryConfig类属于org.javamoney.moneta.spi包,在下文中一共展示了MonetaryConfig类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import org.javamoney.moneta.spi.MonetaryConfig; //导入依赖的package包/类
public void load() {
Map<String, String> config = MonetaryConfig.getConfig();
Set<String> loadServices = new HashSet<>();
for (String key : config.keySet()) {
if (isLoadClass(key)) {
String resource = key.substring(LOAD.length());
resource = resource.substring(0, resource.length() - ('.' + TYPE).length());
loadServices.add(resource);
}
}
for (String loadService : loadServices) {
try {
initResource(loadService, config);
} catch (Exception e) {
LOG.log(Level.SEVERE, "Failed to initialize/register resource: " + loadService, e);
}
}
}
示例2: getDefaultProviderChain
import org.javamoney.moneta.spi.MonetaryConfig; //导入依赖的package包/类
/**
* This default implementation simply returns all providers defined in arbitrary order.
*
* @return the default provider chain, never null.
*/
@Override
public List<String> getDefaultProviderChain() {
List<String> provList = new ArrayList<>();
String defaultChain = MonetaryConfig.getConfig().get("currencies.default-chain");
if(defaultChain!=null) {
String[] items = defaultChain.split(",");
for (String item : items) {
if (getProviderNames().contains(item.trim())) {
provList.add(item);
} else {
Logger.getLogger(getClass().getName())
.warning("Ignoring non existing default provider: " + item);
}
}
}
else{
for(CurrencyProviderSpi currencyProviderSpi: Bootstrap.getServices(CurrencyProviderSpi.class)) {
provList.add(currencyProviderSpi.getProviderName());
}
}
return provList;
}
示例3: getDefaultProviderChain
import org.javamoney.moneta.spi.MonetaryConfig; //导入依赖的package包/类
@Override
public List<String> getDefaultProviderChain() {
List<String> provList = new ArrayList<>();
String defaultChain = MonetaryConfig.getConfig().get("conversion.default-chain");
if(defaultChain!=null) {
String[] items = defaultChain.split(",");
for (String item : items) {
if (getProviderNames().contains(item.trim())) {
provList.add(item);
} else {
LOG.warning("Ignoring non existing default provider: " + item);
}
}
}
else{
for(ExchangeRateProvider p: Bootstrap.getServices(ExchangeRateProvider.class)) {
provList.add(p.getContext().getProviderName());
}
}
return provList;
}
示例4: getDefaultProviderChain
import org.javamoney.moneta.spi.MonetaryConfig; //导入依赖的package包/类
/**
* This default implementation simply returns all providers defined in arbitrary order.
*
* @return the default provider chain, never null.
*/
@Override
public List<String> getDefaultProviderChain() {
List<String> provList = new ArrayList<>();
String defaultChain = MonetaryConfig.getConfig().get("currencies.default-chain");
if(defaultChain!=null) {
String[] items = defaultChain.split(",");
for (String item : items) {
if (getProviderNames().contains(item.trim())) {
provList.add(item);
} else {
Logger.getLogger(getClass().getName())
.warning("Ignoring non existing default provider: " + item);
}
}
}
else{
Bootstrap.getServices(CurrencyProviderSpi.class).forEach(
p -> provList.add(p.getProviderName())
);
}
return provList;
}
示例5: getDefaultProviderChain
import org.javamoney.moneta.spi.MonetaryConfig; //导入依赖的package包/类
@Override
public List<String> getDefaultProviderChain() {
List<String> provList = new ArrayList<>();
String defaultChain = MonetaryConfig.getConfig().get("conversion.default-chain");
if(defaultChain!=null) {
String[] items = defaultChain.split(",");
for (String item : items) {
if (getProviderNames().contains(item.trim())) {
provList.add(item);
} else {
LOG.warning("Ignoring non existing default provider: " + item);
}
}
}
else{
Bootstrap.getServices(ExchangeRateProvider.class).forEach(
p -> provList.add(p.getContext().getProviderName())
);
}
return provList;
}
示例6: getContext
import org.javamoney.moneta.spi.MonetaryConfig; //导入依赖的package包/类
public MonetaryContext getContext() {
try {
Map<String, String> config = MonetaryConfig.getConfig();
String value = config.get("org.javamoney.moneta.Money.defaults.precision");
if (value!=null) {
return createMonetaryContextNonNullConfig(config, Integer.parseInt(value));
} else {
return createContextWithConfig(config);
}
} catch (Exception e) {
Logger.getLogger(DefaultMonetaryContextFactory.class.getName())
.log(Level.SEVERE, "Error evaluating default NumericContext, using default (NumericContext.NUM64).", e);
return MonetaryContextBuilder.of(Money.class).set(MathContext.DECIMAL64).build();
}
}
示例7: checkNumber
import org.javamoney.moneta.spi.MonetaryConfig; //导入依赖的package包/类
/**
* Internal method to check for correct number parameter.
*
* @param number the number to be checked, including null..
* @throws NullPointerException If the number is null
* @throws java.lang.ArithmeticException If the number exceeds the capabilities of this class.
*/
protected void checkNumber(Number number) {
Objects.requireNonNull(number, "Number is required.");
// numeric check for overflow...
if (number.longValue() > MAX_BD.longValue()) {
throw new ArithmeticException("Value exceeds maximal value: " + MAX_BD);
}
BigDecimal bd = MoneyUtils.getBigDecimal(number);
if (bd.precision() > MAX_BD.precision()) {
throw new ArithmeticException("Precision exceeds maximal precision: " + MAX_BD.precision());
}
if (bd.scale() > SCALE) {
String val = MonetaryConfig.getConfig()
.get("org.javamoney.moneta.FastMoney.enforceScaleCompatibility");
if(val==null){
val = "false";
}
if (Boolean.parseBoolean(val)) {
throw new ArithmeticException("Scale of " + bd + " exceeds maximal scale: " + SCALE);
} else {
if (LOG.isLoggable(Level.FINEST)) {
LOG.finest("Scale exceeds maximal scale of FastMoney (" + SCALE +
"), implicit rounding will be applied to " + number);
}
}
}
}
示例8: getScale
import org.javamoney.moneta.spi.MonetaryConfig; //导入依赖的package包/类
@Override
protected int getScale(String key) {
String string = MonetaryConfig.getConfig().getOrDefault(
key, "-1");
if (string.isEmpty()) {
return -1;
} else {
try {
return Integer.valueOf(string);
} catch (NumberFormatException e) {
return -1;
}
}
}
示例9: getContext
import org.javamoney.moneta.spi.MonetaryConfig; //导入依赖的package包/类
public MonetaryContext getContext() {
try {
Map<String, String> config = MonetaryConfig.getConfig();
String value = config.get("org.javamoney.moneta.Money.defaults.precision");
if (Objects.nonNull(value)) {
return createMonetaryContextNonNullConfig(config, Integer.parseInt(value));
} else {
return createContextWithConfig(config);
}
} catch (Exception e) {
Logger.getLogger(DefaultMonetaryContextFactory.class.getName())
.log(Level.SEVERE, "Error evaluating default NumericContext, using default (NumericContext.NUM64).", e);
return MonetaryContextBuilder.of(Money.class).set(MathContext.DECIMAL64).build();
}
}