当前位置: 首页>>代码示例>>Java>>正文


Java DefaultNumberValue类代码示例

本文整理汇总了Java中org.javamoney.moneta.spi.DefaultNumberValue的典型用法代码示例。如果您正苦于以下问题:Java DefaultNumberValue类的具体用法?Java DefaultNumberValue怎么用?Java DefaultNumberValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DefaultNumberValue类属于org.javamoney.moneta.spi包,在下文中一共展示了DefaultNumberValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNumberInsignificanceForRates

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
@Test
public void testNumberInsignificanceForRates(){
	ExchangeRate rateFromString = new ExchangeRateBuilder(ConversionContext.HISTORIC_CONVERSION)
			.setBase(Monetary.getCurrency("USD"))
			.setTerm(Monetary.getCurrency("EUR"))
			.setFactor(DefaultNumberValue.of(new BigDecimal("1.1")))
			.build();

	ExchangeRate rateFromDouble = new ExchangeRateBuilder(ConversionContext.HISTORIC_CONVERSION)
			.setBase(Monetary.getCurrency("USD"))
			.setTerm(Monetary.getCurrency("EUR"))
			.setFactor(DefaultNumberValue.of(1.1))
			.build();

	assertEquals(rateFromDouble, rateFromString, "Rates are not equal for same factor.");
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:17,代码来源:ExchangeRateBuilderTest.java

示例2: addRate

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
private void addRate(CurrencyUnit term, LocalDate localDate, Number rate, boolean inverse) {
    RateType rateType = RateType.HISTORIC;
    ExchangeRateBuilder builder =
        new ExchangeRateBuilder(ConversionContextBuilder.create(context, rateType).set(localDate).build());
    builder.setBase(inverse ? term : USFederalReserveRateProvider.BASE_CURRENCY);
    builder.setTerm(inverse ? USFederalReserveRateProvider.BASE_CURRENCY : term);
    builder.setFactor(DefaultNumberValue.of(rate));
    ExchangeRate exchangeRate = builder.build();
    if(inverse) {
        exchangeRate = USFederalReserveRateProvider.reverse(exchangeRate);
    }
    Map<String, ExchangeRate> rateMap = this.historicRates.get(localDate);
    if (Objects.isNull(rateMap)) {
        synchronized (this.historicRates) {
            rateMap = Optional.ofNullable(this.historicRates.get(localDate)).orElse(new ConcurrentHashMap<>());
            this.historicRates.putIfAbsent(localDate, rateMap);
        }
    }
    rateMap.put(term.getCurrencyCode(), exchangeRate);
}
 
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:21,代码来源:USFederalReserveRateReadingHandler.java

示例3: addRate

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
private void addRate(YahooQuoteItemInformation information) {

        final ExchangeRateBuilder builder = new ExchangeRateBuilder(
        		ConversionContextBuilder.create(context, RateType.DEFERRED).build());
        builder.setBase(YahooAbstractRateProvider.BASE_CURRENCY);
        builder.setTerm(information.getCurrency());
        builder.setFactor(DefaultNumberValue.of(information.getValue()));
        final ExchangeRate exchangeRate = builder.build();

        Map<String, ExchangeRate> rateMap = this.excangeRates.get(information.getLocalDate());
        if (Objects.isNull(rateMap)) {
            synchronized (this.excangeRates) {
                rateMap = Optional.ofNullable(this.excangeRates.get(information.getLocalDate())).orElse(new ConcurrentHashMap<>());
                this.excangeRates.putIfAbsent(information.getLocalDate(), rateMap);
            }
        }
        rateMap.put(information.getCurrency().getCurrencyCode(), exchangeRate);

    }
 
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:20,代码来源:YahooRateReadingHandler.java

示例4: buildExchangeRate

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
private ExchangeRate buildExchangeRate(CurrencyUnitPair pair, Ticker ticker) {
    return new ExchangeRateBuilder(name, RateType.DEFERRED)
            .setBase(pair.getBase())
            .setTerm(pair.getTarget())
            .setFactor(DefaultNumberValue.of(ticker.getLast()))
            .build();
}
 
开发者ID:ConsensusJ,项目名称:consensusj,代码行数:8,代码来源:BaseXChangeExchangeRateProvider.java

示例5: getExchangeRate

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
@Override
public ExchangeRate getExchangeRate(ConversionQuery query) {
       if (query.getBaseCurrency().getCurrencyCode().equals(query.getCurrency().getCurrencyCode())) {
           ExchangeRateBuilder builder = new ExchangeRateBuilder(getContext().getProviderName(), RateType.OTHER)
                   .setBase(query.getBaseCurrency());
           builder.setTerm(query.getCurrency());
           builder.setFactor(DefaultNumberValue.of(BigDecimal.ONE));
           return builder.build();
       }
       return null;
   }
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:12,代码来源:IdentityRateProvider.java

示例6: getReversed

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
@Override
public ExchangeRate getReversed(ExchangeRate rate) {
    if (rate.getContext().getProviderName().equals(CONTEXT.getProviderName())) {
        return new ExchangeRateBuilder(rate.getContext()).setTerm(rate.getBaseCurrency())
                .setBase(rate.getCurrency()).setFactor(new DefaultNumberValue(BigDecimal.ONE)).build();
    }
    return null;
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:9,代码来源:IdentityRateProvider.java

示例7: createExchangeRate

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
private ExchangeRate createExchangeRate(ConversionQuery query,
                                        ExchangeRateBuilder builder, ExchangeRate sourceRate,
                                        ExchangeRate target) {

    if (areBothBaseCurrencies(query)) {
        builder.setFactor(DefaultNumberValue.ONE);
        return builder.build();
    } else if (BASE_CURRENCY_CODE.equals(query.getCurrency().getCurrencyCode())) {
        if (sourceRate==null) {
            return null;
        }
        return reverse(sourceRate);
    } else if (BASE_CURRENCY_CODE.equals(query.getBaseCurrency()
            .getCurrencyCode())) {
        return target;
    } else {
        // Get Conversion base as derived rate: base -> EUR -> term
        ExchangeRate rate1 = getExchangeRate(
                query.toBuilder().setTermCurrency(Monetary.getCurrency(BASE_CURRENCY_CODE)).build());
        ExchangeRate rate2 = getExchangeRate(
                query.toBuilder().setBaseCurrency(Monetary.getCurrency(BASE_CURRENCY_CODE))
                        .setTermCurrency(query.getCurrency()).build());
        if (rate1!=null && rate2!=null) {
            builder.setFactor(multiply(rate1.getFactor(), rate2.getFactor()));
            builder.setRateChain(rate1, rate2);
            return builder.build();
        }
        throw new CurrencyConversionException(query.getBaseCurrency(),
                query.getCurrency(), sourceRate.getContext());
    }
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:32,代码来源:ECBAbstractRateProvider.java

示例8: reverse

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
private ExchangeRate reverse(ExchangeRate rate) {
    if (rate==null) {
        throw new IllegalArgumentException("Rate null is not reversible.");
    }
    return new ExchangeRateBuilder(rate).setRate(rate).setBase(rate.getCurrency()).setTerm(rate.getBaseCurrency())
            .setFactor(divide(DefaultNumberValue.ONE, rate.getFactor(), MathContext.DECIMAL64)).build();
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:8,代码来源:ECBAbstractRateProvider.java

示例9: equalsTest

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
@Test
public void equalsTest() {
    DefaultNumberValue factor = new DefaultNumberValue(1.1);
    DefaultNumberValue bigDecimalFactor = new DefaultNumberValue(new BigDecimal("1.1"));

    ExchangeRate rate1 = new ExchangeRateBuilder("myprovider", RateType.ANY)
            .setBase(EUR)
            .setTerm(GBP)
            .setFactor(factor)
            .build();

    ExchangeRate rate2 = new ExchangeRateBuilder("myprovider", RateType.ANY)
            .setBase(EUR)
            .setTerm(GBP)
            .setFactor(factor)
            .build();

    ExchangeRate rate3 = new ExchangeRateBuilder("myprovider", RateType.ANY)
            .setBase(EUR)
            .setTerm(GBP)
            .setFactor(bigDecimalFactor)
            .build();

    assertEquals(rate1, rate2, "Rates with same factor");
    assertEquals(rate1, rate3, "Rates with numerically equal factor");
    assertEquals(rate1.hashCode(), rate2.hashCode(), "Hashes with same factor");
    assertEquals(rate1.hashCode(), rate3.hashCode(), "Hashes with numerically equal factor");
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:29,代码来源:ExchangeRateSimpleTest.java

示例10: equalsTest

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
@Test
public void equalsTest() {
	DefaultNumberValue factor = new DefaultNumberValue(1.1);
	DefaultNumberValue bigDecimalFactor = new DefaultNumberValue(new BigDecimal("1.1"));
	CurrencyUnit EUR = Monetary.getCurrency("EUR");
	CurrencyUnit GBP = Monetary.getCurrency("GBP");
	ExchangeRate rate1 = new ExchangeRateBuilder("myprovider", RateType.ANY)
			.setBase(EUR)
			.setTerm(GBP)
			.setFactor(factor)
			.build();

	ExchangeRate rate2 = new ExchangeRateBuilder("myprovider", RateType.ANY)
			.setBase(EUR)
			.setTerm(GBP)
			.setFactor(factor)
			.build();

	ExchangeRate rate3 = new ExchangeRateBuilder("myprovider", RateType.ANY)
			.setBase(EUR)
			.setTerm(GBP)
			.setFactor(bigDecimalFactor)
			.build();

	assertEquals(rate1, rate2, "Rates with same factor");
	assertEquals(rate1, rate3, "Rates with numerically equal factor");
	assertEquals(rate1.hashCode(), rate2.hashCode(), "Hashes with same factor");
	assertEquals(rate1.hashCode(), rate3.hashCode(), "Hashes with numerically equal factor");
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:30,代码来源:ExchangeRateBuilderTest.java

示例11: deserialize

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
@Override
public M deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
    NumberValue amount = null;
    CurrencyUnit currency = null;

    while (parser.nextToken() != JsonToken.END_OBJECT) {
        final String field = parser.getCurrentName();

        parser.nextToken();

        if (field.equals(names.getAmount())) {
            amount = DefaultNumberValue.of(context.readValue(parser, BigDecimal.class));
        } else if (field.equals(names.getCurrency())) {
            currency = context.readValue(parser, CurrencyUnit.class);
        } else if (field.equals(names.getFormatted())) {
            //noinspection UnnecessaryContinue
            continue;
        } else if (context.isEnabled(FAIL_ON_UNKNOWN_PROPERTIES)) {
            throw UnrecognizedPropertyException.from(parser, MonetaryAmount.class, field,
                    Arrays.<Object>asList(names.getAmount(), names.getCurrency(), names.getFormatted()));
        } else {
            parser.skipChildren();
        }
    }

    checkPresent(parser, amount, names.getAmount());
    checkPresent(parser, currency, names.getCurrency());

    return factory.create(amount, currency);
}
 
开发者ID:zalando,项目名称:jackson-datatype-money,代码行数:31,代码来源:MonetaryAmountDeserializer.java

示例12: getExchangeRate

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
@Override
public ExchangeRate getExchangeRate(CurrencyUnit base, CurrencyUnit term) {
    if (!SupportedCurrency.contains(base.getCurrencyCode()) || SupportedCurrency.contains(term.getCurrencyCode())) {
        return null;
    }
    final NumberValue  factor = DefaultNumberValue.of(currentRates.get(base.getCurrencyCode()));
    if (factor!=null) {
    	return new ExchangeRateBuilder("Bitcoin.de", RATE_TYPE).setBase(base).setTerm(term).setFactor(factor).build();
    } else {
    	return null;
    }
}
 
开发者ID:JavaMoney,项目名称:javamoney-shelter,代码行数:13,代码来源:BitcoinDeRateProvider.java

示例13: createExchangeRate

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
private ExchangeRate createExchangeRate(ConversionQuery query, ExchangeRateBuilder builder,
    ExchangeRate sourceRate, ExchangeRate target) {

    if (areBothBaseCurrencies(query)) {
        builder.setFactor(DefaultNumberValue.ONE);
        return builder.build();
    } else if (BASE_CURRENCY_CODE.equals(query.getCurrency().getCurrencyCode())) {
        if (Objects.isNull(sourceRate)) {
            return null;
        }
        return reverse(sourceRate);
    } else if (BASE_CURRENCY_CODE.equals(query.getBaseCurrency().getCurrencyCode())) {
        return target;
    } else {

        ExchangeRate rate1 =
            getExchangeRate(query.toBuilder().setTermCurrency(Monetary.getCurrency(BASE_CURRENCY_CODE)).build());
        ExchangeRate rate2 =
            getExchangeRate(query.toBuilder().setBaseCurrency(Monetary.getCurrency(BASE_CURRENCY_CODE))
                .setTermCurrency(query.getCurrency()).build());
        if (Objects.nonNull(rate1) && Objects.nonNull(rate2)) {
            builder.setFactor(multiply(rate1.getFactor(), rate2.getFactor()));
            builder.setRateChain(rate1, rate2);
            return builder.build();
        }
        throw new CurrencyConversionException(query.getBaseCurrency(), query.getCurrency(), sourceRate.getContext());
    }
}
 
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:29,代码来源:USFederalReserveRateProvider.java

示例14: reverse

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
protected static ExchangeRate reverse(ExchangeRate rate) {
    if (Objects.isNull(rate)) {
        throw new IllegalArgumentException("Rate null is not reversible.");
    }
    return new ExchangeRateBuilder(rate).setRate(rate).setBase(rate.getCurrency()).setTerm(rate.getBaseCurrency())
        .setFactor(divide(DefaultNumberValue.ONE, rate.getFactor(), MathContext.DECIMAL64)).build();
}
 
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:8,代码来源:USFederalReserveRateProvider.java

示例15: createExchangeRate

import org.javamoney.moneta.spi.DefaultNumberValue; //导入依赖的package包/类
private ExchangeRate createExchangeRate(ConversionQuery query,
		ExchangeRateBuilder builder, ExchangeRate sourceRate,
		ExchangeRate target) {

	if (areBothBaseCurrencies(query)) {
		builder.setFactor(DefaultNumberValue.ONE);
		return builder.build();
	} else if (BASE_CURRENCY_CODE.equals(query.getCurrency()
			.getCurrencyCode())) {
		if (Objects.isNull(sourceRate)) {
			return null;
		}

		return reverse(sourceRate);
	} else if (BASE_CURRENCY_CODE.equals(query.getBaseCurrency()
			.getCurrencyCode())) {
		return target;
	} else {

		ExchangeRate rate1 = getExchangeRate(query.toBuilder()
				.setTermCurrency(Monetary.getCurrency(BASE_CURRENCY_CODE))
				.build());

		ExchangeRate rate2 = getExchangeRate(query.toBuilder()
				.setBaseCurrency(Monetary.getCurrency(BASE_CURRENCY_CODE))
				.setTermCurrency(query.getCurrency()).build());

		if (Objects.nonNull(rate1) && Objects.nonNull(rate2)) {
			builder.setFactor(multiply(rate1.getFactor(), rate2.getFactor()));
			builder.setRateChain(rate1, rate2);
			return builder.build();
		}

		throw new CurrencyConversionException(query.getBaseCurrency(),
				query.getCurrency(), sourceRate.getContext());
	}
}
 
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:38,代码来源:YahooAbstractRateProvider.java


注:本文中的org.javamoney.moneta.spi.DefaultNumberValue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。