9
9
.
10
10
. The NumberUtils Class was Coded by : Alexandre BOLOT
11
11
.
12
- . Last Modified : 02 /12/17 01 :03
12
+ . Last Modified : 10 /12/17 23 :03
13
13
.
14
14
15
15
...............................................................................................................................*/
@@ -172,7 +172,7 @@ public static boolean isInBounds (double minBound, double value, double maxBound
172
172
{
173
173
if (maxBound < minBound ) throw new IllegalArgumentException ("maxBound < minBound" );
174
174
175
- return minBound < value && value > maxBound ;
175
+ return minBound < value && value < maxBound ;
176
176
}
177
177
178
178
/**
@@ -190,10 +190,11 @@ public static <T> boolean isInBounds (T minBound, T value, T maxBound, Comparato
190
190
Objects .requireNonNull (value , "value is null" );
191
191
Objects .requireNonNull (minBound , "minBound is null" );
192
192
Objects .requireNonNull (maxBound , "maxBound is null" );
193
+ Objects .requireNonNull (comparator , "comparator is null" );
193
194
194
195
if (comparator .compare (maxBound , minBound ) < 0 ) throw new IllegalArgumentException ("maxBound < minBound" );
195
196
196
- return comparator .compare (value , minBound ) > 0 && comparator .compare (value , maxBound ) < 0 ;
197
+ return comparator .compare (minBound , value ) < 0 && comparator .compare (value , maxBound ) < 0 ;
197
198
}
198
199
199
200
/**
@@ -214,43 +215,15 @@ public static <T extends Comparable<T>> boolean isInBounds (T minBound, T value,
214
215
215
216
if (maxBound .compareTo (minBound ) < 0 ) throw new IllegalArgumentException ("maxBound < minBound" );
216
217
217
- return value .compareTo (minBound ) > 0 && value .compareTo (maxBound ) < 0 ;
218
+ return minBound .compareTo (value ) < 0 && value .compareTo (maxBound ) < 0 ;
218
219
}
219
220
//endregion
220
221
221
- //region ============ min (x7) ===================
222
- public static int min (int [] array )
223
- {
224
- if (array .length == 0 ) throw new IllegalArgumentException ("Array is empty" );
225
- if (array .length == 1 ) return array [0 ];
226
-
227
- int min = Integer .MAX_VALUE ;
228
-
229
- for (int i : array )
230
- {
231
- if (i < min ) min = i ;
232
- }
233
-
234
- return min ;
235
- }
236
-
237
- public static float min (float [] array )
238
- {
239
- if (array .length == 0 ) throw new IllegalArgumentException ("Array is empty" );
240
- if (array .length == 1 ) return array [0 ];
241
-
242
- float min = Float .MAX_VALUE ;
243
-
244
- for (Float i : array )
245
- {
246
- if (i < min ) min = i ;
247
- }
248
-
249
- return min ;
250
- }
251
-
222
+ //region ============ min (x5) ===================
252
223
public static double min (double [] array )
253
224
{
225
+ Objects .requireNonNull (array );
226
+
254
227
if (array .length == 0 ) throw new IllegalArgumentException ("Array is empty" );
255
228
if (array .length == 1 ) return array [0 ];
256
229
@@ -266,6 +239,8 @@ public static double min (double[] array)
266
239
267
240
public static <T > T min (T [] array , Comparator <T > comparator )
268
241
{
242
+ Objects .requireNonNull (array );
243
+
269
244
if (array .length == 0 ) throw new IllegalArgumentException ("Array is empty" );
270
245
if (array .length == 1 ) return array [0 ];
271
246
@@ -281,6 +256,8 @@ public static <T> T min (T[] array, Comparator<T> comparator)
281
256
282
257
public static <T > T min (Collection <T > collection , Comparator <T > comparator )
283
258
{
259
+ Objects .requireNonNull (collection );
260
+
284
261
if (collection .size () == 0 ) throw new IllegalArgumentException ("Collection is empty" );
285
262
if (collection .size () == 1 ) return (T ) collection .toArray ()[0 ];
286
263
@@ -296,6 +273,8 @@ public static <T> T min (Collection<T> collection, Comparator<T> comparator)
296
273
297
274
public static <T extends Comparable <T >> T min (T [] array )
298
275
{
276
+ Objects .requireNonNull (array );
277
+
299
278
if (array .length == 0 ) throw new IllegalArgumentException ("Array is empty" );
300
279
if (array .length == 1 ) return array [0 ];
301
280
@@ -311,6 +290,8 @@ public static <T extends Comparable<T>> T min (T[] array)
311
290
312
291
public static <T extends Comparable <T >> T min (Collection <T > collection )
313
292
{
293
+ Objects .requireNonNull (collection );
294
+
314
295
if (collection .size () == 0 ) throw new IllegalArgumentException ("Collection is empty" );
315
296
if (collection .size () == 1 ) return (T ) collection .toArray ()[0 ];
316
297
@@ -325,35 +306,7 @@ public static <T extends Comparable<T>> T min (Collection<T> collection)
325
306
}
326
307
//endregion
327
308
328
- //region ============ max (x7) ===================
329
- public static int max (int [] array )
330
- {
331
- if (array .length == 0 ) throw new IllegalArgumentException ("Array is empty" );
332
-
333
- int max = Integer .MIN_VALUE ;
334
-
335
- for (int i : array )
336
- {
337
- if (i > max ) max = i ;
338
- }
339
-
340
- return max ;
341
- }
342
-
343
- public static float max (float [] array )
344
- {
345
- if (array .length == 0 ) throw new IllegalArgumentException ("Array is empty" );
346
-
347
- float max = Integer .MIN_VALUE ;
348
-
349
- for (float i : array )
350
- {
351
- if (i > max ) max = i ;
352
- }
353
-
354
- return max ;
355
- }
356
-
309
+ //region ============ max (x5) ===================
357
310
public static double max (double [] array )
358
311
{
359
312
if (array .length == 0 ) throw new IllegalArgumentException ("Array is empty" );
0 commit comments