|
14 | 14 | * See the License for the specific language governing permissions and |
15 | 15 | * limitations under the License. |
16 | 16 | */ |
17 | | - |
18 | 17 | package org.apache.commons.mail2.core; |
19 | 18 |
|
20 | 19 | import java.io.OutputStreamWriter; |
|
36 | 35 | * @since 1.0 |
37 | 36 | */ |
38 | 37 | public class EmailException extends Exception { |
39 | | - |
40 | 38 | /** Serializable version identifier. */ |
41 | 39 | private static final long serialVersionUID = 5550674499282474616L; |
42 | 40 |
|
| 41 | + /** |
| 42 | + * Throws an EmailException if the supplier evaluates to true. |
| 43 | + * |
| 44 | + * @param <T> the subject type to return if we don't throw. |
| 45 | + * @param test test condition. |
| 46 | + * @param subject the subject to return if we don't throw. |
| 47 | + * @param message the exception message. |
| 48 | + * @return the given subject. |
| 49 | + * @throws EmailException if the supplier evaluates to true. |
| 50 | + */ |
43 | 51 | public static <T> T check(final Supplier<Boolean> test, final T subject, final Supplier<String> message) throws EmailException { |
44 | 52 | if (test.get()) { |
45 | 53 | throw new EmailException(message.get()); |
46 | 54 | } |
47 | 55 | return subject; |
48 | 56 | } |
49 | 57 |
|
| 58 | + /** |
| 59 | + * Throws an EmailException if the collection is empty. |
| 60 | + * |
| 61 | + * @param <T> the type of elements in the collection. |
| 62 | + * @param value the value to test. |
| 63 | + * @param message the exception message. |
| 64 | + * @return the given subject. |
| 65 | + * @throws EmailException if the collection is empty. |
| 66 | + */ |
50 | 67 | public static <T> Collection<T> checkNonEmpty(final Collection<T> value, final Supplier<String> message) throws EmailException { |
51 | 68 | return check(() -> EmailUtils.isEmpty(value), value, message); |
52 | 69 | } |
53 | 70 |
|
| 71 | + /** |
| 72 | + * Throws an EmailException if the string is empty. |
| 73 | + * |
| 74 | + * @param message the exception message. |
| 75 | + * @param value the value to test. |
| 76 | + * @return the given subject. |
| 77 | + * @throws EmailException if the string is empty. |
| 78 | + */ |
54 | 79 | public static String checkNonEmpty(final String value, final Supplier<String> message) throws EmailException { |
55 | 80 | return check(() -> EmailUtils.isEmpty(value), value, message); |
56 | 81 | } |
57 | 82 |
|
| 83 | + /** |
| 84 | + * Throws an EmailException if the array is empty. |
| 85 | + * |
| 86 | + * @param <T> the array type. |
| 87 | + * @param message the exception message. |
| 88 | + * @param value the value to test. |
| 89 | + * @return the given subject. |
| 90 | + * @throws EmailException if the array is empty. |
| 91 | + */ |
58 | 92 | public static <T> T[] checkNonEmpty(final T[] value, final Supplier<String> message) throws EmailException { |
59 | 93 | return check(() -> EmailUtils.isEmpty(value), value, message); |
60 | 94 | } |
61 | 95 |
|
62 | | - public static <T> T checkNonNull(final T test, final Supplier<String> message) throws EmailException { |
63 | | - if (test == null) { |
| 96 | + /** |
| 97 | + * Throws an EmailException if the value is null. |
| 98 | + * |
| 99 | + * @param <T> the value type. |
| 100 | + * @param message the exception message. |
| 101 | + * @param value the value to test. |
| 102 | + * @return the given subject. |
| 103 | + * @throws EmailException if the value is null. |
| 104 | + */ |
| 105 | + public static <T> T checkNonNull(final T value, final Supplier<String> message) throws EmailException { |
| 106 | + if (value == null) { |
64 | 107 | throw new EmailException(message.get()); |
65 | 108 | } |
66 | | - return test; |
| 109 | + return value; |
67 | 110 | } |
68 | 111 |
|
69 | 112 | /** |
|
0 commit comments