1
1
package CodingUtils ;
2
2
3
- import org .jetbrains .annotations .Contract ;
4
3
import org .jetbrains .annotations .NotNull ;
5
4
6
5
import java .util .Collection ;
11
10
.
12
11
. The AssertUtils Class was Coded by : Alexandre BOLOT
13
12
.
14
- . Last Modified : 20/01 /18 00:24
13
+ . Last Modified : 20/02 /18 23:18
15
14
.
16
15
17
16
...............................................................................................................................*/
@@ -25,19 +24,13 @@ public class AssertUtils
25
24
<hr>
26
25
<h2>Tests if the parameters are null</h2>
27
26
<h3>If one of them is —> throws IllegalArgumentException, with index of first null object as message.</h3>
28
- <br>
29
- Note : asserts [array] isn't null.<br>
30
- <br>
31
27
<hr>
32
28
33
29
@param array Array of T objects to test for null value
34
30
*/
35
- @ Contract ("null -> fail" )
36
31
@ SafeVarargs
37
- public static <T > void assertNotNull (T ... array )
32
+ public static <T > void assertNotNull (@ NotNull T ... array )
38
33
{
39
- if (array == null ) throw new IllegalArgumentException ("List of Objects is null" );
40
-
41
34
for (int i = 0 ; i < array .length ; i ++)
42
35
{
43
36
if (array [i ] == null ) throw new IllegalArgumentException ("Element at index " + i + " is null" );
@@ -52,10 +45,9 @@ public static <T> void assertNotNull (T... array)
52
45
53
46
@param t The ‹T› object to test for null value
54
47
*/
55
- @ Contract ("null-> fail" )
56
- public static <T > void assertNotNull (T t )
48
+ public static <T > void assertNotNull (@ NotNull T t )
57
49
{
58
- if ( t == null ) throw new IllegalArgumentException ( "Param is null" );
50
+ //Nothing to do, @NotNull does the job :D
59
51
}
60
52
//endregion
61
53
@@ -65,47 +57,38 @@ public static <T> void assertNotNull (T t)
65
57
<hr>
66
58
<h2>Tests if [string] is empty</h2>
67
59
<h3>If it is —> throws IllegalArgumentException.</h3>
68
- Note : already asserts [string] isn't null.<br>
69
- <br>
70
60
<hr>
71
61
72
62
@param string The String to test for empty value
73
63
*/
74
64
public static void assertNotEmpty (@ NotNull String string )
75
65
{
76
- if (string == null ) throw new IllegalArgumentException ("String is null" );
77
66
if (string .isEmpty ()) throw new IllegalArgumentException ("String is empty" );
78
67
}
79
68
80
69
/**
81
70
<hr>
82
71
<h2>Tests if [list] is empty</h2>
83
72
<h3>If it is —> throws IllegalArgumentException.</h3>
84
- Note : already asserts [list] isn't null.<br>
85
- <br>
86
73
<hr>
87
74
88
75
@param collection The List to test for empty value
89
76
*/
90
77
public static void assertNotEmpty (@ NotNull Collection collection )
91
78
{
92
- if (collection == null ) throw new IllegalArgumentException ("Collection is null" );
93
79
if (collection .isEmpty ()) throw new IllegalArgumentException ("List is empty" );
94
80
}
95
81
96
82
/**
97
83
<hr>
98
84
<h2>Tests if [map] is empty</h2>
99
85
<h3>If it is —> throws IllegalArgumentException.</h3>
100
- Note : already asserts [map] isn't null.<br>
101
- <br>
102
86
<hr>
103
87
104
88
@param map The Map to test for empty value
105
89
*/
106
90
public static void assertNotEmpty (@ NotNull Map map )
107
91
{
108
- if (map == null ) throw new IllegalArgumentException ("Map is null" );
109
92
if (map .isEmpty ()) throw new IllegalArgumentException ("Map is empty" );
110
93
}
111
94
//endregion
@@ -115,7 +98,7 @@ public static void assertNotEmpty (@NotNull Map map)
115
98
/**
116
99
<hr>
117
100
<h2>Tests if [val] is > 0</h2>
118
- <h3>If it is —> throws IllegalArgumentException.</h3>
101
+ <h3>If it's not —> throws IllegalArgumentException.</h3>
119
102
<hr>
120
103
121
104
@param val The value to test for strict positivity
0 commit comments