This repository has been archived by the owner on Jan 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ValidateHelper.java
171 lines (160 loc) · 3.31 KB
/
ValidateHelper.java
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package org.xueyao.utils.base;
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
/**
* 判断对象、字符串、集合是否为空、不为空
*
* @Author:chenssy
* @date:2014年8月4日
*/
public final class ValidateHelper {
/**
* 判断数组是否为空
* @author chenssy
* @date Dec 23, 2013
* @param array
* @return boolean
*/
@SuppressWarnings("unused")
private static <T> boolean isEmptyArray(T[] array){
if (array == null || array.length == 0){
return true;
}
else{
return false;
}
}
/**
* 判断数组是否不为空
* @author chenssy
* @date Dec 23, 2013
* @param array
* @return boolean
*/
public static <T> boolean isNotEmptyArray(T[] array){
if (array != null && array.length > 0){
return true;
}
else{
return false;
}
}
/**
* 判断字符串是否为空
* @author chenssy
* @date Dec 23, 2013
* @param string
* @return boolean
*/
public static boolean isEmptyString(String string){
if (string == null || string.length() == 0){
return true;
}
else{
return false;
}
}
/**
* 判断字符串是否不为空
* @author chenssy
* @date Dec 23, 2013
* @param string
* @return boolean
*/
public static boolean isNotEmptyString(String string){
if (string != null && string.length() > 0){
return true;
}
else{
return false;
}
}
/**
* 判断集合是否为空
* @author chenssy
* @date Dec 26, 2013
* @param collection
* @return boolean
*/
public static boolean isEmptyCollection(Collection<?> collection){
if (collection == null || collection.isEmpty()){
return true;
}
else{
return false;
}
}
/**
* 判断集合是否不为空
* @author chenssy
* @date Dec 26, 2013
* @param collection
* @return boolean
*/
public static boolean isNotEmptyCollection(Collection<?> collection){
if (collection != null && !collection.isEmpty()){
return true;
}
else{
return false;
}
}
/**
* 判断map集合是否不为空
* @author chenssy
* @date Dec 26, 2013
* @param map
* @return boolean
*/
@SuppressWarnings("rawtypes")
public static boolean isNotEmptyMap(Map map){
if (map != null && !map.isEmpty()){
return true;
}
else{
return false;
}
}
/**
* 判断map集合是否为空
* @author ming.chen
* @date Dec 26, 2013
* @param map
* @return boolean
*/
@SuppressWarnings("rawtypes")
public static boolean isEmptyMap(Map map){
if (map == null || map.isEmpty()){
return true;
}
else{
return false;
}
}
/**
* 检验对象是否为空,String 中只有空格在对象中也算空.
* @param object
* @return 为空返回true,否则false.
*/
@SuppressWarnings("rawtypes")
public static boolean isEmpty(Object object) {
if (null == object)
return true;
else if (object instanceof String)
return "".equals(object.toString().trim());
else if (object instanceof Iterable)
return !((Iterable) object).iterator().hasNext();
else if (object.getClass().isArray())
return Array.getLength(object) == 0;
else if (object instanceof Map)
return ((Map) object).size() == 0;
else if (Number.class.isAssignableFrom(object.getClass()))
return false;
else if (Date.class.isAssignableFrom(object.getClass()))
return false;
else
return false;
}
}