|
12 | 12 | */ |
13 | 13 | package com.labs64.netlicensing.util; |
14 | 14 |
|
| 15 | +import com.labs64.netlicensing.exception.MalformedArgumentsException; |
| 16 | + |
15 | 17 | /** |
16 | 18 | * Common utilities for precondition checking. |
17 | 19 | */ |
18 | 20 | public class CheckUtils { |
19 | 21 |
|
20 | 22 | /** |
21 | 23 | * Ensures that an object reference is not null. |
22 | | - * |
| 24 | + * |
23 | 25 | * @param object |
24 | 26 | * object to check |
25 | 27 | * @param msg |
26 | 28 | * exception message |
27 | | - * @throws IllegalArgumentException |
| 29 | + * @throws MalformedArgumentsException |
28 | 30 | * if object is null |
29 | 31 | */ |
30 | | - public static void notNull(final Object object, final String msg) { |
| 32 | + private static void notNull(final Object object, final String msg) throws MalformedArgumentsException { |
31 | 33 | if (object == null) { |
32 | | - throw new IllegalArgumentException(msg); |
| 34 | + throw new MalformedArgumentsException(msg); |
33 | 35 | } |
34 | 36 | } |
35 | 37 |
|
36 | 38 | /** |
37 | 39 | * Ensures that a string is not null or empty. |
38 | | - * |
| 40 | + * |
39 | 41 | * @param string |
40 | 42 | * string to check |
41 | 43 | * @param msg |
42 | 44 | * exception message |
43 | | - * @throws IllegalArgumentException |
| 45 | + * @throws MalformedArgumentsException |
44 | 46 | * if string is null or empty |
45 | 47 | */ |
46 | | - public static void notEmpty(final String string, final String msg) { |
| 48 | + private static void notEmpty(final String string, final String msg) throws MalformedArgumentsException { |
47 | 49 | if (string == null || string.length() == 0) { |
48 | | - throw new IllegalArgumentException(msg); |
| 50 | + throw new MalformedArgumentsException(msg); |
49 | 51 | } |
50 | 52 | } |
51 | 53 |
|
52 | 54 | /** |
53 | 55 | * Ensures that an object reference passed as a parameter to the calling method is not null. |
54 | | - * |
| 56 | + * |
55 | 57 | * @param parameter |
56 | 58 | * param to check |
57 | 59 | * @param parameterName |
58 | 60 | * name of the parameter |
59 | | - * @throws IllegalArgumentException |
| 61 | + * @throws MalformedArgumentsException |
60 | 62 | * if parameter is null |
61 | 63 | */ |
62 | | - public static void paramNotNull(final Object parameter, final String parameterName) { |
| 64 | + public static void paramNotNull(final Object parameter, final String parameterName) |
| 65 | + throws MalformedArgumentsException { |
63 | 66 | notNull(parameter, String.format("Parameter '%s' cannot be null", parameterName)); |
64 | 67 | } |
65 | 68 |
|
66 | 69 | /** |
67 | 70 | * Ensures that a string passed as a parameter to the calling method is not null or empty. |
68 | | - * |
| 71 | + * |
69 | 72 | * @param parameter |
70 | 73 | * param to check |
71 | 74 | * @param parameterName |
72 | 75 | * name of the parameter |
73 | | - * @throws IllegalArgumentException |
| 76 | + * @throws MalformedArgumentsException |
74 | 77 | * if parameter is null or empty |
75 | 78 | */ |
76 | | - public static void paramNotEmpty(final String parameter, final String parameterName) { |
| 79 | + public static void paramNotEmpty(final String parameter, final String parameterName) |
| 80 | + throws MalformedArgumentsException { |
77 | 81 | notEmpty(parameter, String.format("Parameter '%s' cannot be null or empty string", parameterName)); |
78 | 82 | } |
79 | 83 |
|
|
0 commit comments