AssertUtils.java
2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.diligrp.assistant.shared.util;
import java.util.Collection;
import java.util.Map;
/**
* 断言工具类
*/
public class AssertUtils {
public static void notNull(Object object) {
notNull(object, "[Assertion failed] - this argument is required; it must not be null");
}
public static void notNull(Object object, String message) {
if (object == null) {
throw new IllegalArgumentException(message);
}
}
public static void notEmpty(String str) {
notEmpty(str, "[Assertion failed] - this argument is required; it must not be empty");
}
public static void notEmpty(String str, String message) {
if (ObjectUtils.isEmpty(str)) {
throw new IllegalArgumentException(message);
}
}
public static void isTrue(boolean expression, String message) {
if (!expression) {
throw new IllegalArgumentException(message);
}
}
public static void isTrue(boolean expression) {
isTrue(expression, "[Assertion failed] - this expression must be true");
}
public static void notEmpty(Collection<?> collection, String message) {
if (collection == null || collection.isEmpty()) {
throw new IllegalArgumentException(message);
}
}
public static void notEmpty(Collection<?> collection) {
notEmpty(collection, "[Assertion failed] - this collection must not be empty");
}
public static void notEmpty(Map<?, ?> map, String message) {
if (map == null || map.isEmpty()) {
throw new IllegalArgumentException(message);
}
}
public static void notEmpty(Object[] array) {
notEmpty(array, "[Assertion failed] - this array must not be empty");
}
public static void notEmpty(Object[] array, String message) {
if (array == null || array.length == 0) {
throw new IllegalArgumentException(message);
}
}
public static void notEmpty(Map<?, ?> map) {
notEmpty(map, "[Assertion failed] - this map must not be empty");
}
}