Skip to content

Commit 9bac246

Browse files
committed
Changing verification of params
1 parent d9163cc commit 9bac246

File tree

6 files changed

+178
-178
lines changed

6 files changed

+178
-178
lines changed

src/main/java/CodingUtils/AssertUtils.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package CodingUtils;
22

3-
import org.jetbrains.annotations.Contract;
43
import org.jetbrains.annotations.NotNull;
54

65
import java.util.Collection;
@@ -11,7 +10,7 @@
1110
.
1211
. The AssertUtils Class was Coded by : Alexandre BOLOT
1312
.
14-
. Last Modified : 20/01/18 00:24
13+
. Last Modified : 20/02/18 23:18
1514
.
1615
. Contact : [email protected]
1716
...............................................................................................................................*/
@@ -25,19 +24,13 @@ public class AssertUtils
2524
<hr>
2625
<h2>Tests if the parameters are null</h2>
2726
<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>
3127
<hr>
3228
3329
@param array Array of T objects to test for null value
3430
*/
35-
@Contract ("null -> fail")
3631
@SafeVarargs
37-
public static <T> void assertNotNull (T... array)
32+
public static <T> void assertNotNull (@NotNull T... array)
3833
{
39-
if (array == null) throw new IllegalArgumentException("List of Objects is null");
40-
4134
for (int i = 0; i < array.length; i++)
4235
{
4336
if (array[i] == null) throw new IllegalArgumentException("Element at index " + i + " is null");
@@ -52,10 +45,9 @@ public static <T> void assertNotNull (T... array)
5245
5346
@param t The ‹T› object to test for null value
5447
*/
55-
@Contract ("null-> fail")
56-
public static <T> void assertNotNull (T t)
48+
public static <T> void assertNotNull (@NotNull T t)
5749
{
58-
if (t == null) throw new IllegalArgumentException("Param is null");
50+
//Nothing to do, @NotNull does the job :D
5951
}
6052
//endregion
6153

@@ -65,47 +57,38 @@ public static <T> void assertNotNull (T t)
6557
<hr>
6658
<h2>Tests if [string] is empty</h2>
6759
<h3>If it is —> throws IllegalArgumentException.</h3>
68-
Note : already asserts [string] isn't null.<br>
69-
<br>
7060
<hr>
7161
7262
@param string The String to test for empty value
7363
*/
7464
public static void assertNotEmpty (@NotNull String string)
7565
{
76-
if (string == null) throw new IllegalArgumentException("String is null");
7766
if (string.isEmpty()) throw new IllegalArgumentException("String is empty");
7867
}
7968

8069
/**
8170
<hr>
8271
<h2>Tests if [list] is empty</h2>
8372
<h3>If it is —> throws IllegalArgumentException.</h3>
84-
Note : already asserts [list] isn't null.<br>
85-
<br>
8673
<hr>
8774
8875
@param collection The List to test for empty value
8976
*/
9077
public static void assertNotEmpty (@NotNull Collection collection)
9178
{
92-
if (collection == null) throw new IllegalArgumentException("Collection is null");
9379
if (collection.isEmpty()) throw new IllegalArgumentException("List is empty");
9480
}
9581

9682
/**
9783
<hr>
9884
<h2>Tests if [map] is empty</h2>
9985
<h3>If it is —> throws IllegalArgumentException.</h3>
100-
Note : already asserts [map] isn't null.<br>
101-
<br>
10286
<hr>
10387
10488
@param map The Map to test for empty value
10589
*/
10690
public static void assertNotEmpty (@NotNull Map map)
10791
{
108-
if (map == null) throw new IllegalArgumentException("Map is null");
10992
if (map.isEmpty()) throw new IllegalArgumentException("Map is empty");
11093
}
11194
//endregion
@@ -115,7 +98,7 @@ public static void assertNotEmpty (@NotNull Map map)
11598
/**
11699
<hr>
117100
<h2>Tests if [val] is > 0</h2>
118-
<h3>If it is —> throws IllegalArgumentException.</h3>
101+
<h3>If it's not —> throws IllegalArgumentException.</h3>
119102
<hr>
120103
121104
@param val The value to test for strict positivity

src/main/java/CodingUtils/FormatUtils.java

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
.
1111
. The FormatUtils Class was Coded by : Alexandre BOLOT
1212
.
13-
. Last Modified : 20/01/18 00:30
13+
. Last Modified : 20/02/18 23:18
1414
.
1515
. Contact : [email protected]
1616
...............................................................................................................................*/
@@ -23,19 +23,13 @@ public class FormatUtils
2323
/**
2424
<hr>
2525
<h2>Formats [string] with FirstUpperCase format</h2>
26-
Note : asserts [string] param isn't null.<br>
27-
<br>
2826
<hr>
2927
3028
@param string String to format
3129
@return A formatted version of [string]
3230
*/
3331
public static String toFirstUpperCase (@NotNull String string)
3432
{
35-
//region --> Check params
36-
if (string == null) throw new IllegalArgumentException("String param is null");
37-
//endregion
38-
3933
if (string.isEmpty()) return string;
4034
if (string.length() == 1) return string.toUpperCase();
4135

@@ -48,18 +42,12 @@ public static String toFirstUpperCase (@NotNull String string)
4842
/**
4943
<hr>
5044
<h2>Prints all elements of the [objects] list</h2>
51-
Note : asserts [objects] param isn't null.<br>
52-
<br>
5345
<hr>
5446
5547
@param objects List of T objects to be printed
5648
*/
5749
public static <T> void printListFancy (@NotNull List<T> objects, @NotNull String start, @NotNull String separator, @NotNull String end)
5850
{
59-
//region --> Check params
60-
if (objects == null) throw new IllegalArgumentException("List param is null");
61-
//endregion
62-
6351
if (objects.isEmpty())
6452
{
6553
System.out.print(start + end);
@@ -82,35 +70,13 @@ public static <T> void printListFancy (@NotNull List<T> objects, @NotNull String
8270
/**
8371
<hr>
8472
<h2>Prints all elements of the [objects] array</h2>
85-
Note : asserts [objects] param isn't null.<br>
86-
<br>
8773
<hr>
8874
8975
@param objects Array of T objects to be printed
9076
*/
9177
public static <T> void printArrayFancy (@NotNull T[] objects, @NotNull String start, @NotNull String separator, @NotNull String end)
9278
{
93-
//region --> Check params
94-
if (objects == null) throw new IllegalArgumentException("Array param is null");
95-
//endregion
96-
97-
if (objects.length == 0)
98-
{
99-
System.out.print(start + end);
100-
return;
101-
}
102-
103-
StringBuilder str = new StringBuilder();
104-
105-
str.append(start == null ? "" : start);
106-
107-
Arrays.asList(objects).forEach(o -> str.append(o).append(separator == null ? "" : separator));
108-
109-
if (separator != null) str.deleteCharAt(str.length() - separator.length());
110-
111-
str.append(end == null ? "" : end);
112-
113-
System.out.print(str.toString());
79+
printListFancy(Arrays.asList(objects), start, separator, end);
11480
}
11581
//endregion
11682
}

0 commit comments

Comments
 (0)