1- /**
2- * Copyright (c) 2012, 2017, Anatole Tresch, Werner Keil and others by the @author tag.
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5- * use this file except in compliance with the License. You may obtain a copy of
6- * the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13- * License for the specific language governing permissions and limitations under
14- * the License.
1+ /*
2+ Copyright (c) 2012, 2017, Anatole Tresch, Werner Keil and others by the @author tag.
3+
4+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+ use this file except in compliance with the License. You may obtain a copy of
6+ the License at
7+
8+ http://www.apache.org/licenses/LICENSE-2.0
9+
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+ License for the specific language governing permissions and limitations under
14+ the License.
1515 */
1616package org .javamoney .moneta ;
1717
@@ -263,8 +263,8 @@ public static FastMoney zero(CurrencyUnit currency) {
263263 * @param currency the currency, not null
264264 * @param amountMinor the amount of money in the minor division of the currency
265265 * @return the monetary amount from minor units
266- * @see {@link CurrencyUnit#getDefaultFractionDigits()}
267- * @see {@link FastMoney#ofMinor(CurrencyUnit, long, int)}
266+ * @see CurrencyUnit#getDefaultFractionDigits()
267+ * @see FastMoney#ofMinor(CurrencyUnit, long, int)
268268 * @throws NullPointerException when the currency is null
269269 * @throws IllegalArgumentException when {@link CurrencyUnit#getDefaultFractionDigits()} is lesser than zero.
270270 * @since 1.0.1
@@ -280,7 +280,7 @@ public static FastMoney ofMinor(CurrencyUnit currency, long amountMinor) {
280280 * @param amountMinor the amount of money in the minor division of the currency
281281 * @param factionDigits number of digits
282282 * @return the monetary amount from minor units
283- * @see {@link CurrencyUnit#getDefaultFractionDigits()}
283+ * @see CurrencyUnit#getDefaultFractionDigits()
284284 * @throws NullPointerException when the currency is null
285285 * @throws IllegalArgumentException when the factionDigits is negative
286286 * @since 1.0.1
@@ -395,7 +395,7 @@ private void checkAmountParameter(MonetaryAmount amount) {
395395 */
396396 @ Override
397397 public FastMoney divide (Number divisor ) {
398- if (Money . isInfinityAndNotNaN (divisor )) {
398+ if (isInfinityAndNotNaN (divisor )) {
399399 return new FastMoney (0L , getCurrency ());
400400 }
401401 checkNumber (divisor );
@@ -405,13 +405,28 @@ public FastMoney divide(Number divisor) {
405405 return new FastMoney (Math .round (this .number / divisor .doubleValue ()), getCurrency ());
406406 }
407407
408+ /**
409+ * Just to don't break the compatibility.
410+ * Don't use it
411+ * @param number
412+ */
413+ private static boolean isInfinityAndNotNaN (Number number ) {
414+ if (Double .class == number .getClass () || Float .class == number .getClass ()) {
415+ double dValue = number .doubleValue ();
416+ if (!Double .isNaN (dValue ) && Double .isInfinite (dValue )) {
417+ return true ;
418+ }
419+ }
420+ return false ;
421+ }
422+
408423 /*
409424 * (non-Javadoc)
410425 * @see MonetaryAmount#divideAndRemainder(java.lang.Number)
411426 */
412427 @ Override
413428 public FastMoney [] divideAndRemainder (Number divisor ) {
414- if (Money . isInfinityAndNotNaN (divisor )) {
429+ if (isInfinityAndNotNaN (divisor )) {
415430 FastMoney zero = new FastMoney (0L , getCurrency ());
416431 return new FastMoney []{zero , zero };
417432 }
@@ -427,7 +442,7 @@ public FastMoney[] divideAndRemainder(Number divisor) {
427442 */
428443 @ Override
429444 public FastMoney divideToIntegralValue (Number divisor ) {
430- if (Money . isInfinityAndNotNaN (divisor )) {
445+ if (isInfinityAndNotNaN (divisor )) {
431446 return new FastMoney (0L , getCurrency ());
432447 }
433448 checkNumber (divisor );
@@ -440,7 +455,7 @@ public FastMoney divideToIntegralValue(Number divisor) {
440455
441456 @ Override
442457 public FastMoney multiply (Number multiplicand ) {
443- Money . checkNoInfinityOrNaN (multiplicand );
458+ checkNoInfinityOrNaN (multiplicand );
444459 checkNumber (multiplicand );
445460 if (isOne (multiplicand )) {
446461 return this ;
@@ -449,6 +464,17 @@ public FastMoney multiply(Number multiplicand) {
449464 getCurrency ());
450465 }
451466
467+ private static void checkNoInfinityOrNaN (Number number ) {
468+ if (Double .class == number .getClass () || Float .class == number .getClass ()) {
469+ double dValue = number .doubleValue ();
470+ if (Double .isNaN (dValue )) {
471+ throw new ArithmeticException ("Not a valid input: NaN." );
472+ } else if (Double .isInfinite (dValue )) {
473+ throw new ArithmeticException ("Not a valid input: INFINITY: " + dValue );
474+ }
475+ }
476+ }
477+
452478 private long multiplyExact (long num1 , long num2 ) {
453479 if (num1 ==0 || num2 ==0 ){
454480 return 0 ;
@@ -833,9 +859,8 @@ public static FastMoney from(MonetaryAmount amount) {
833859 *
834860 * @param text the text to parse not null
835861 * @return FastMoney instance
836- * @throws NullPointerException
837- * @throws NumberFormatException
838- * @throws javax.money.UnknownCurrencyException
862+ * @throws NumberFormatException if the amount is not a number
863+ * @throws javax.money.UnknownCurrencyException if the currency is not resolvable
839864 */
840865 public static FastMoney parse (CharSequence text ) {
841866 return parse (text , DEFAULT_FORMATTER );
0 commit comments