Skip to content

Commit

Permalink
OPEN - task 2: JIRA Placeholder - JAVAMONEY-67
Browse files Browse the repository at this point in the history
  • Loading branch information
keilw committed Mar 2, 2014
1 parent a3b3d4d commit fdfa099
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
50 changes: 23 additions & 27 deletions src/main/java/javax/money/convert/ExchangeRate.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
* DOWNLOADING THIS SPECIFICATION, YOU ACCEPT THE TERMS AND CONDITIONS OF THE
* AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY IT, SELECT THE "DECLINE"
* BUTTON AT THE BOTTOM OF THIS PAGE. Specification: JSR-354 Money and Currency
* API ("Specification") Copyright (c) 2012-2013, Credit Suisse All rights
* API ("Specification") Copyright (c) 2012-2014, Credit Suisse All rights
* reserved.
*/
package javax.money.convert;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import javax.money.CurrencyUnit;
import javax.money.NumberValue;

/**
* This class models an exchange rate between two currencies. Hereby
Expand Down Expand Up @@ -66,7 +66,7 @@
* <ul>
* <li>The base {@link CurrencyUnit}
* <li>The target {@link CurrencyUnit}
* <li>The factor (BigDecimal)
* <li>The factor (NumberValue)
* <li>The {@link ConversionContext}
* <li>The rate chain
* </ul>
Expand Down Expand Up @@ -96,7 +96,7 @@ public final class ExchangeRate implements Serializable,
/**
* The conversion factor.
*/
private final BigDecimal factor;
private final NumberValue factor;
/**
* The {@link ConversionContext}
*/
Expand All @@ -114,15 +114,15 @@ public final class ExchangeRate implements Serializable,
* the number
* @return a BigDecimal representing the number.
*/
private BigDecimal getBigDecimal(Number num) {
if (num instanceof BigDecimal) {
return (BigDecimal) num;
}
if (num instanceof Long) {
return BigDecimal.valueOf(num.longValue());
}
return BigDecimal.valueOf(num.doubleValue());
}
// private BigDecimal getBigDecimal(Number num) {
// if (num instanceof BigDecimal) {
// return (BigDecimal) num;
// }
// if (num instanceof Long) {
// return BigDecimal.valueOf(num.longValue());
// }
// return BigDecimal.valueOf(num.doubleValue());
// }

/**
* Creates a new instance with a custom chain of exchange rate type, e.g. or
Expand Down Expand Up @@ -153,7 +153,7 @@ private ExchangeRate(Builder builder) {
"exchangeRateType may not be null.");
this.base = builder.base;
this.term = builder.term;
this.factor = getBigDecimal(builder.factor);
this.factor = builder.factor;
this.conversionContext = builder.conversionContext;
setExchangeRateChain(builder.rateChain);
}
Expand Down Expand Up @@ -211,7 +211,7 @@ public final CurrencyUnit getTerm() {
*
* @return the bid factor for this exchange rate, or {@code null}.
*/
public final BigDecimal getFactor() {
public final NumberValue getFactor() {
return this.factor;
}

Expand Down Expand Up @@ -373,7 +373,7 @@ public static class Builder {
/**
* The conversion factor.
*/
private BigDecimal factor;
private NumberValue factor;
/**
* The chain of invovled rates.
*/
Expand Down Expand Up @@ -447,16 +447,12 @@ public Builder setRateChain(ExchangeRate... exchangeRates) {
* the factor.
* @return The builder instance.
*/
public Builder setFactor(Number factor) {
if (factor != null) {
if (factor instanceof BigDecimal) {
this.factor = (BigDecimal) factor;
} else {
this.factor = BigDecimal.valueOf(factor.doubleValue());
}
}
return this;
}
// public Builder setFactor(Number factor) {
// if (factor != null) {
// this.factor = new DefaultNumberValue(factor);
// }
// return this;
// }

/**
* Sets the conversion factor, as the factor
Expand All @@ -466,7 +462,7 @@ public Builder setFactor(Number factor) {
* the factor.
* @return The builder instance.
*/
public Builder setFactor(BigDecimal factor) {
public Builder setFactor(NumberValue factor) {
this.factor = factor;
return this;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/javax/money/convert/ExchangeRateProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* DOWNLOADING THIS SPECIFICATION, YOU ACCEPT THE TERMS AND CONDITIONS OF THE
* AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY IT, SELECT THE "DECLINE"
* BUTTON AT THE BOTTOM OF THIS PAGE. Specification: JSR-354 Money and Currency
* API ("Specification") Copyright (c) 2012-2013, Credit Suisse All rights
* API ("Specification") Copyright (c) 2012-2014, Credit Suisse All rights
* reserved.
*/
package javax.money.convert;
Expand All @@ -25,6 +25,7 @@
* Implementations of this class must neither be immutable nor serializable.
*
* @author Anatole Tresch
* @author Werner Keil
*/
public interface ExchangeRateProvider {

Expand Down

0 comments on commit fdfa099

Please sign in to comment.