Skip to content

Commit b2176e1

Browse files
committed
Quality fixes, added Javadocs.
1 parent df5dc1c commit b2176e1

File tree

57 files changed

+306
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+306
-319
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
JSR 354: Money and Currency Reference Implementation
2-
====================================================
1+
JSR 354: Money and Currency Moneta Reference Implementation
2+
===========================================================
33
JSR 354 provides an API for representing, transporting, and performing comprehensive calculations with Money and Currency.
4-
This module implements JSR 354 Money & Currency. Hereby basic implementations of amounts, currency and roundings are provided.
4+
This module (moneta) implements JSR 354 Money & Currency. Hereby basic implementations of amounts, currency and roundings
5+
are provided.
56

67
See the JCP detail page:
78
http://jcp.org/en/jsr/detail?id=354

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
<artifactId>moneta</artifactId>
2626
<version>1.0</version>
27-
<packaging>jar</packaging>
27+
<packaging>bundle</packaging>
2828

2929
<name>Moneta (JSR 354 RI)</name>
3030
<url>http://javamoney.org</url>

src/main/java/org/javamoney/moneta/DefaultExchangeRate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class DefaultExchangeRate implements ExchangeRate, Serializable, Comparable<Exch
111111
/**
112112
* The full chain, at least one instance long.
113113
*/
114-
private List<ExchangeRate> chain = new ArrayList<>();
114+
private final List<ExchangeRate> chain = new ArrayList<>();
115115

116116

117117
/**
@@ -266,7 +266,7 @@ public boolean equals(Object obj) {
266266
}
267267
if (obj instanceof DefaultExchangeRate) {
268268
DefaultExchangeRate other = (DefaultExchangeRate) obj;
269-
return Objects.equals(base, other.base) && Objects.equals(chain, other.chain) &&
269+
return Objects.equals(base, other.base) &&
270270
Objects.equals(conversionContext, other.conversionContext) &&
271271
Objects.equals(factor, other.factor) && Objects.equals(term, other.term);
272272
}

src/main/java/org/javamoney/moneta/ExchangeRateType.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public enum ExchangeRateType implements ExchangeRateProviderSupplier {
4747
"IDENT",
4848
"Exchange rate rate with factor one for identical base/term currencies");
4949

50-
private String type;
50+
private final String type;
5151

52-
private String description;
52+
private final String description;
5353

5454
ExchangeRateType(String type, String description) {
5555
this.type = type;
@@ -61,7 +61,6 @@ public String get() {
6161
return type;
6262
}
6363

64-
@Override
6564
public String getDescription() {
6665
return description;
6766
}

src/main/java/org/javamoney/moneta/FastMoney.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,8 @@ private boolean isOne(Number number) {
443443
* @see javax.money.MonetaryAmount#scaleByPowerOfTen(int)
444444
*/
445445
@Override
446-
public FastMoney scaleByPowerOfTen(int n) {
447-
return new FastMoney(getNumber().numberValue(BigDecimal.class).scaleByPowerOfTen(n), getCurrency(), true);
446+
public FastMoney scaleByPowerOfTen(int power) {
447+
return new FastMoney(getNumber().numberValue(BigDecimal.class).scaleByPowerOfTen(power), getCurrency(), true);
448448
}
449449

450450
/*
@@ -648,7 +648,7 @@ public String toString() {
648648
* @throws NullPointerException If the number is null
649649
* @throws java.lang.ArithmeticException If the number exceeds the capabilities of this class.
650650
*/
651-
protected void checkNumber(Number number) {
651+
private void checkNumber(Number number) {
652652
Objects.requireNonNull(number, "Number is required.");
653653
// numeric check for overflow...
654654
if (number.longValue() > MAX_BD.longValue()) {
@@ -731,71 +731,71 @@ public static FastMoney parse(CharSequence text, MonetaryAmountFormat formatter)
731731
return from(formatter.parse(text));
732732
}
733733

734-
private static ToStringMonetaryAmountFormat DEFAULT_FORMATTER = ToStringMonetaryAmountFormat
734+
private static final ToStringMonetaryAmountFormat DEFAULT_FORMATTER = ToStringMonetaryAmountFormat
735735
.of(ToStringMonetaryAmountFormatStyle.FAST_MONEY);
736736

737737
private BigDecimal getBigDecimal() {
738738
return BigDecimal.valueOf(this.number).movePointLeft(SCALE);
739739
}
740740

741741
@Override
742-
public FastMoney multiply(double amount) {
743-
Money.checkNoInfinityOrNaN(amount);
744-
if (amount == 1.0) {
742+
public FastMoney multiply(double multiplicand) {
743+
Money.checkNoInfinityOrNaN(multiplicand);
744+
if (multiplicand == 1.0) {
745745
return this;
746746
}
747-
if (amount == 0.0) {
747+
if (multiplicand == 0.0) {
748748
return new FastMoney(0, this.currency);
749749
}
750-
return new FastMoney(Math.round(this.number * amount), this.currency);
750+
return new FastMoney(Math.round(this.number * multiplicand), this.currency);
751751
}
752752

753753
@Override
754-
public FastMoney divide(long amount) {
755-
if (amount == 1L) {
754+
public FastMoney divide(long divisor) {
755+
if (divisor == 1L) {
756756
return this;
757757
}
758-
return new FastMoney(this.number / amount, this.currency);
758+
return new FastMoney(this.number / divisor, this.currency);
759759
}
760760

761761
@Override
762-
public FastMoney divide(double number) {
763-
if (Money.isInfinityAndNotNaN(number)) {
762+
public FastMoney divide(double divisor) {
763+
if (Money.isInfinityAndNotNaN(divisor)) {
764764
return new FastMoney(0L, getCurrency());
765765
}
766-
if (number == 1.0d) {
766+
if (divisor == 1.0d) {
767767
return this;
768768
}
769-
return new FastMoney(Math.round(this.number / number), getCurrency());
769+
return new FastMoney(Math.round(this.number / divisor), getCurrency());
770770
}
771771

772772
@Override
773-
public FastMoney remainder(long number) {
774-
return remainder(BigDecimal.valueOf(number));
773+
public FastMoney remainder(long divisor) {
774+
return remainder(BigDecimal.valueOf(divisor));
775775
}
776776

777777
@Override
778-
public FastMoney remainder(double amount) {
779-
if (Money.isInfinityAndNotNaN(amount)) {
778+
public FastMoney remainder(double divisor) {
779+
if (Money.isInfinityAndNotNaN(divisor)) {
780780
return new FastMoney(0L, getCurrency());
781781
}
782-
return remainder(new BigDecimal(String.valueOf(amount)));
782+
return remainder(new BigDecimal(String.valueOf(divisor)));
783783
}
784784

785785
@Override
786-
public FastMoney[] divideAndRemainder(long amount) {
787-
return divideAndRemainder(BigDecimal.valueOf(amount));
786+
public FastMoney[] divideAndRemainder(long divisor) {
787+
return divideAndRemainder(BigDecimal.valueOf(divisor));
788788
}
789789

790790
@Override
791-
public FastMoney[] divideAndRemainder(double amount) {
792-
if (Money.isInfinityAndNotNaN(amount)) {
791+
public FastMoney[] divideAndRemainder(double divisor) {
792+
if (Money.isInfinityAndNotNaN(divisor)) {
793793
FastMoney zero = new FastMoney(0L, getCurrency());
794794
return new FastMoney[]{zero, zero};
795-
} else if (amount == Double.NaN) {
795+
} else if (divisor == Double.NaN) {
796796
throw new ArithmeticException("Not a number: NaN.");
797797
}
798-
return divideAndRemainder(new BigDecimal(String.valueOf(amount)));
798+
return divideAndRemainder(new BigDecimal(String.valueOf(divisor)));
799799
}
800800

801801
@Override

src/main/java/org/javamoney/moneta/Money.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public final class Money implements MonetaryAmount, Comparable<MonetaryAmount>,
9191
/**
9292
* The numeric part of this amount.
9393
*/
94-
private BigDecimal number;
94+
private final BigDecimal number;
9595

9696
/**
9797
* Creates a new instance os {@link Money}.
@@ -517,12 +517,12 @@ public Money plus() {
517517
* @see javax.money.MonetaryAmount#subtract(javax.money.MonetaryAmount)
518518
*/
519519
@Override
520-
public Money subtract(MonetaryAmount subtrahend) {
521-
MoneyUtils.checkAmountParameter(subtrahend, this.currency);
522-
if (subtrahend.isZero()) {
520+
public Money subtract(MonetaryAmount amount) {
521+
MoneyUtils.checkAmountParameter(amount, this.currency);
522+
if (amount.isZero()) {
523523
return this;
524524
}
525-
return new Money(this.number.subtract(subtrahend.getNumber().numberValue(BigDecimal.class)), getCurrency());
525+
return new Money(this.number.subtract(amount.getNumber().numberValue(BigDecimal.class)), getCurrency());
526526
}
527527

528528
/*
@@ -558,8 +558,8 @@ public Money remainder(Number divisor) {
558558
* @see javax.money.MonetaryAmount#scaleByPowerOfTen(int)
559559
*/
560560
@Override
561-
public Money scaleByPowerOfTen(int n) {
562-
return new Money(this.number.scaleByPowerOfTen(n), getCurrency());
561+
public Money scaleByPowerOfTen(int power) {
562+
return new Money(this.number.scaleByPowerOfTen(power), getCurrency());
563563
}
564564

565565
/*
@@ -834,7 +834,7 @@ public static Money parse(CharSequence text, MonetaryAmountFormat formatter) {
834834
return from(formatter.parse(text));
835835
}
836836

837-
private static ToStringMonetaryAmountFormat DEFAULT_FORMATTER = ToStringMonetaryAmountFormat
837+
private static final ToStringMonetaryAmountFormat DEFAULT_FORMATTER = ToStringMonetaryAmountFormat
838838
.of(ToStringMonetaryAmountFormatStyle.MONEY);
839839

840840
public static void checkNoInfinityOrNaN(Number number) {

src/main/java/org/javamoney/moneta/RoundedMoney.java

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public final class RoundedMoney implements MonetaryAmount, Comparable<MonetaryAm
7373
/**
7474
* The rounding to be done.
7575
*/
76-
private MonetaryOperator rounding;
76+
private final MonetaryOperator rounding;
7777

7878

7979
/**
@@ -119,15 +119,18 @@ public RoundedMoney(Number number, CurrencyUnit currency, MonetaryContext contex
119119
this.rounding = Monetary
120120
.getRounding(RoundingQueryBuilder.of().setScale(scale).set(rm).build());
121121
}
122+
else{
123+
this.rounding = Monetary.getDefaultRounding();
124+
}
122125
} else {
123126
b.set(mc.getRoundingMode());
124127
b.set("scale", 2);
125128
this.rounding =
126129
Monetary.getRounding(RoundingQueryBuilder.of().set(mc).setScale(2).build());
127130
}
128-
if (this.rounding == null) {
129-
this.rounding = Monetary.getDefaultRounding();
130-
}
131+
}
132+
else{
133+
this.rounding = Monetary.getDefaultRounding();
131134
}
132135
}
133136
b.set("MonetaryRounding", this.rounding);
@@ -401,12 +404,12 @@ public RoundedMoney plus() {
401404
* @see javax.money.MonetaryAmount#subtract(javax.money.MonetaryAmount)
402405
*/
403406
@Override
404-
public RoundedMoney subtract(MonetaryAmount subtrahend) {
405-
MoneyUtils.checkAmountParameter(subtrahend, this.currency);
406-
if (subtrahend.isZero()) {
407+
public RoundedMoney subtract(MonetaryAmount amount) {
408+
MoneyUtils.checkAmountParameter(amount, this.currency);
409+
if (amount.isZero()) {
407410
return this;
408411
}
409-
return new RoundedMoney(this.number.subtract(subtrahend.getNumber().numberValue(BigDecimal.class),
412+
return new RoundedMoney(this.number.subtract(amount.getNumber().numberValue(BigDecimal.class),
410413
Optional.ofNullable(
411414
this.monetaryContext.get(MathContext.class)).orElse(MathContext.DECIMAL64)),
412415
this.currency, this.rounding);
@@ -446,8 +449,8 @@ public RoundedMoney remainder(Number divisor) {
446449
* @see javax.money.MonetaryAmount#scaleByPowerOfTen(int)
447450
*/
448451
@Override
449-
public RoundedMoney scaleByPowerOfTen(int n) {
450-
return new RoundedMoney(this.number.scaleByPowerOfTen(n), this.currency, this.rounding);
452+
public RoundedMoney scaleByPowerOfTen(int power) {
453+
return new RoundedMoney(this.number.scaleByPowerOfTen(power), this.currency, this.rounding);
451454
}
452455

453456
/*
@@ -669,7 +672,7 @@ public static RoundedMoney parse(CharSequence text, MonetaryAmountFormat formatt
669672
return from(formatter.parse(text));
670673
}
671674

672-
private static ToStringMonetaryAmountFormat DEFAULT_FORMATTER = ToStringMonetaryAmountFormat
675+
private static final ToStringMonetaryAmountFormat DEFAULT_FORMATTER = ToStringMonetaryAmountFormat
673676
.of(ToStringMonetaryAmountFormatStyle.ROUNDED_MONEY);
674677

675678
/*
@@ -815,66 +818,66 @@ private void checkNumber(Number number) {
815818
}
816819

817820
@Override
818-
public RoundedMoney multiply(long amount) {
819-
if (amount == 1L) {
821+
public RoundedMoney multiply(long multiplicand) {
822+
if (multiplicand == 1L) {
820823
return this;
821824
}
822-
return multiply(MoneyUtils.getBigDecimal(amount));
825+
return multiply(MoneyUtils.getBigDecimal(multiplicand));
823826
}
824827

825828
@Override
826-
public RoundedMoney multiply(double amount) {
827-
Money.checkNoInfinityOrNaN(amount);
828-
if (amount == 1.0d) {
829+
public RoundedMoney multiply(double multiplicand) {
830+
Money.checkNoInfinityOrNaN(multiplicand);
831+
if (multiplicand == 1.0d) {
829832
return this;
830833
}
831-
return multiply(MoneyUtils.getBigDecimal(amount));
834+
return multiply(MoneyUtils.getBigDecimal(multiplicand));
832835
}
833836

834837
@Override
835-
public RoundedMoney divide(long amount) {
836-
if (amount == 1L) {
838+
public RoundedMoney divide(long divisor) {
839+
if (divisor == 1L) {
837840
return this;
838841
}
839-
return divide(MoneyUtils.getBigDecimal(amount));
842+
return divide(MoneyUtils.getBigDecimal(divisor));
840843
}
841844

842845
@Override
843-
public RoundedMoney divide(double amount) {
844-
if (Money.isInfinityAndNotNaN(amount)) {
846+
public RoundedMoney divide(double divisor) {
847+
if (Money.isInfinityAndNotNaN(divisor)) {
845848
return new RoundedMoney(0L, getCurrency(), this.monetaryContext, this.rounding);
846849
}
847-
if (amount == 1.0d) {
850+
if (divisor == 1.0d) {
848851
return this;
849852
}
850-
return divide(MoneyUtils.getBigDecimal(amount));
853+
return divide(MoneyUtils.getBigDecimal(divisor));
851854
}
852855

853856
@Override
854-
public RoundedMoney remainder(long amount) {
855-
return remainder(MoneyUtils.getBigDecimal(amount));
857+
public RoundedMoney remainder(long divisor) {
858+
return remainder(MoneyUtils.getBigDecimal(divisor));
856859
}
857860

858861
@Override
859-
public RoundedMoney remainder(double amount) {
860-
if (Money.isInfinityAndNotNaN(amount)) {
862+
public RoundedMoney remainder(double divisor) {
863+
if (Money.isInfinityAndNotNaN(divisor)) {
861864
return new RoundedMoney(0L, getCurrency(), this.monetaryContext, this.rounding);
862865
}
863-
return remainder(MoneyUtils.getBigDecimal(amount));
866+
return remainder(MoneyUtils.getBigDecimal(divisor));
864867
}
865868

866869
@Override
867-
public RoundedMoney[] divideAndRemainder(long amount) {
868-
return divideAndRemainder(MoneyUtils.getBigDecimal(amount));
870+
public RoundedMoney[] divideAndRemainder(long divisor) {
871+
return divideAndRemainder(MoneyUtils.getBigDecimal(divisor));
869872
}
870873

871874
@Override
872-
public RoundedMoney[] divideAndRemainder(double amount) {
873-
if (Money.isInfinityAndNotNaN(amount)) {
875+
public RoundedMoney[] divideAndRemainder(double divisor) {
876+
if (Money.isInfinityAndNotNaN(divisor)) {
874877
RoundedMoney zero = new RoundedMoney(0L, getCurrency(), this.monetaryContext, this.rounding);
875878
return new RoundedMoney[]{zero, zero};
876879
}
877-
return divideAndRemainder(MoneyUtils.getBigDecimal(amount));
880+
return divideAndRemainder(MoneyUtils.getBigDecimal(divisor));
878881
}
879882

880883
@Override

0 commit comments

Comments
 (0)