8
8
import org .apache .commons .math3 .complex .Complex ;
9
9
10
10
/**
11
- * Contains convenience methos for arrays
11
+ * Contains convenience methods for arrays
12
12
*
13
13
* @author roemer
14
14
*/
15
15
public class ArrayHelper {
16
+ private static final String ARRAY_DIMENSION_MISMATCH_MESSAGE =
17
+ "Both arrays may have the same dimension." ;
16
18
17
19
private ArrayHelper () {}
18
20
@@ -45,12 +47,12 @@ public static boolean arrayContainsValue(int[] arr, int value) {
45
47
/**
46
48
* Element wise addition of two double arrays
47
49
*
48
- * @param a Array of double values for the first summand
49
- * @param b Array of double values for the second summand
50
+ * @param a Array of double values for the first addend
51
+ * @param b Array of double values for the second addend
50
52
* @return c Double array with the summation of a and b
51
53
*/
52
54
public static double [] add (double [] a , double [] b ) {
53
- assert a .length == b .length : "Both arrays may have the same dimension." ;
55
+ if ( a .length != b .length ) throw new IllegalArgumentException ( ARRAY_DIMENSION_MISMATCH_MESSAGE ) ;
54
56
double [] c = new double [a .length ];
55
57
for (int i = 0 ; i < c .length ; i ++) {
56
58
c [i ] = a [i ] + b [i ];
@@ -61,12 +63,12 @@ public static double[] add(double[] a, double[] b) {
61
63
/**
62
64
* Element wise addition of two double arrays
63
65
*
64
- * @param a Array of {@link Complex} values for the first summand
65
- * @param b Array of {@link Complex} values for the second summand
66
+ * @param a Array of {@link Complex} values for the first addend
67
+ * @param b Array of {@link Complex} values for the second addend
66
68
* @return c Double array with the summation of a and b
67
69
*/
68
70
public static Complex [] add (Complex [] a , Complex [] b ) {
69
- assert a .length == b .length : "Both arrays may have the same dimension." ;
71
+ if ( a .length != b .length ) throw new IllegalArgumentException ( ARRAY_DIMENSION_MISMATCH_MESSAGE ) ;
70
72
Complex [] c = new Complex [a .length ];
71
73
for (int i = 0 ; i < c .length ; i ++) {
72
74
c [i ] = a [i ].add (b [i ]);
@@ -82,7 +84,7 @@ public static Complex[] add(Complex[] a, Complex[] b) {
82
84
* @return The Array of double values built by subtraction
83
85
*/
84
86
public static double [] subtract (double [] a , double [] b ) {
85
- assert a .length == b .length : "Both arrays may have the same dimension." ;
87
+ if ( a .length != b .length ) throw new IllegalArgumentException ( ARRAY_DIMENSION_MISMATCH_MESSAGE ) ;
86
88
double [] c = new double [a .length ];
87
89
for (int i = 0 ; i < c .length ; i ++) {
88
90
c [i ] = a [i ] - b [i ];
@@ -98,7 +100,7 @@ public static double[] subtract(double[] a, double[] b) {
98
100
* @return The Array of {@link Complex} values built by subtraction
99
101
*/
100
102
public static Complex [] subtract (Complex [] a , Complex [] b ) {
101
- assert a .length == b .length : "Both arrays may have the same dimension." ;
103
+ if ( a .length != b .length ) throw new IllegalArgumentException ( ARRAY_DIMENSION_MISMATCH_MESSAGE ) ;
102
104
Complex [] c = new Complex [a .length ];
103
105
for (int i = 0 ; i < c .length ; i ++) {
104
106
c [i ] = a [i ].subtract (b [i ]);
0 commit comments