You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Judging from the RI the contract of MonetaryAmount#compareTo seems to be to first compare by currency code (not by currency, even though CurrencyUnit is Comparable) before comparing by numeric value. However all the convenience comparison methods #isGreaterThan, #isGreaterThanOrEqualTo, #isLessThan, #isLessThanOrEqualTo, #isEqualTo are specified to throw MonetaryException if the currency code (not the currency) is different.
This may be an issue with the RI and not the API, as the API gives no guidance on how #compareTo should be implemented. However the API requires that #equals considers the currency unit and that best practices are that a.equals(b) implies a.compareTo(b) == 0 .
The text was updated successfully, but these errors were encountered:
A good point.
Comparator can be used for example to sort some amounts in table. And that’s ok to compare amounts with different currencies. So it shouldn’t throw any exceptions for different currencies but instead it should compare by a currency firts.
Judging from the RI the contract of
MonetaryAmount#compareTo
seems to be to first compare by currency code (not by currency, even thoughCurrencyUnit
isComparable
) before comparing by numeric value. However all the convenience comparison methods#isGreaterThan
,#isGreaterThanOrEqualTo
,#isLessThan
,#isLessThanOrEqualTo
,#isEqualTo
are specified to throwMonetaryException
if the currency code (not the currency) is different.This leads to the following behavior:
This may be an issue with the RI and not the API, as the API gives no guidance on how
#compareTo
should be implemented. However the API requires that#equals
considers the currency unit and that best practices are thata.equals(b)
impliesa.compareTo(b) == 0
.The text was updated successfully, but these errors were encountered: