From 5a28357bb55457094123e45646af0e52996f7032 Mon Sep 17 00:00:00 2001 From: Duncan Jones Date: Sat, 10 May 2014 07:22:22 +0000 Subject: [PATCH] Using Validate where possible in math package. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1593679 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/lang3/math/IEEE754rUtils.java | 29 +++++++++---------- .../commons/lang3/math/NumberUtils.java | 6 ++-- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/math/IEEE754rUtils.java b/src/main/java/org/apache/commons/lang3/math/IEEE754rUtils.java index 3fe3b259a..a32ce47c7 100644 --- a/src/main/java/org/apache/commons/lang3/math/IEEE754rUtils.java +++ b/src/main/java/org/apache/commons/lang3/math/IEEE754rUtils.java @@ -16,6 +16,8 @@ */ package org.apache.commons.lang3.math; +import org.apache.commons.lang3.Validate; + /** *

Provides IEEE-754r variants of NumberUtils methods.

* @@ -39,9 +41,9 @@ public class IEEE754rUtils { // Validates input if (array == null) { throw new IllegalArgumentException("The Array must not be null"); - } else if (array.length == 0) { - throw new IllegalArgumentException("Array cannot be empty."); - } + } + Validate.isTrue(array.length != 0, "Array cannot be empty."); + // Finds and returns min double min = array[0]; @@ -65,10 +67,9 @@ public class IEEE754rUtils { // Validates input if (array == null) { throw new IllegalArgumentException("The Array must not be null"); - } else if (array.length == 0) { - throw new IllegalArgumentException("Array cannot be empty."); - } - + } + Validate.isTrue(array.length != 0, "Array cannot be empty."); + // Finds and returns min float min = array[0]; for (int i = 1; i < array.length; i++) { @@ -159,10 +160,9 @@ public class IEEE754rUtils { // Validates input if (array== null) { throw new IllegalArgumentException("The Array must not be null"); - } else if (array.length == 0) { - throw new IllegalArgumentException("Array cannot be empty."); - } - + } + Validate.isTrue(array.length != 0, "Array cannot be empty."); + // Finds and returns max double max = array[0]; for (int j = 1; j < array.length; j++) { @@ -185,10 +185,9 @@ public class IEEE754rUtils { // Validates input if (array == null) { throw new IllegalArgumentException("The Array must not be null"); - } else if (array.length == 0) { - throw new IllegalArgumentException("Array cannot be empty."); - } - + } + Validate.isTrue(array.length != 0, "Array cannot be empty."); + // Finds and returns max float max = array[0]; for (int j = 1; j < array.length; j++) { diff --git a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java index 5a6d28dba..602fabe0e 100644 --- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java +++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java @@ -21,6 +21,7 @@ import java.math.BigDecimal; import java.math.BigInteger; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; /** *

Provides extra functionality for Java Number classes.

@@ -1092,9 +1093,8 @@ public class NumberUtils { private static void validateArray(final Object array) { if (array == null) { throw new IllegalArgumentException("The Array must not be null"); - } else if (Array.getLength(array) == 0) { - throw new IllegalArgumentException("Array cannot be empty."); - } + } + Validate.isTrue(Array.getLength(array) != 0, "Array cannot be empty."); } // 3 param min