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
package util;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.Collection;
import java.util.Map;
/**
* 校验工具类
* @author liruijie@reyun.com
* @date 2015年11月24日
*/
public class ValidateUtil {
/**
* 判断string是否有效
* @param str
* @return
*/
public static boolean isValid(String str) {
if (str == null || "".equals(str.trim())) {
return false;
}
return true;
}
/**
* 判断集合的有效性
* @param col
* @return
*/
@SuppressWarnings("rawtypes")
public static boolean isValid(Collection col) {
if (col == null || col.isEmpty()) {
return false;
}
return true;
}
/**
* 判断map的有效性
* @param map
* @return
*/
@SuppressWarnings("rawtypes")
public static boolean isValid(Map map) {
if (map == null || map.isEmpty()) {
return false;
}
return true;
}
/**
* 判断数组有效性
* @param arr
* @return
*/
public static boolean isValid(Object[] arr) {
if (arr == null || arr.length == 0) {
return false;
}
return true;
}
/**
* 判断对象有效性
* @param obj
* @return
*/
public static boolean isValid(Object obj) {
if (obj == null) {
return false;
}
return true;
}
public static boolean isValid(JSONArray obj) {
if (obj == null) {
return false;
}
if(obj.length()<1){
return false;
}
return true;
}
public static boolean validNotChinese(String str){
return str.matches("^[a-zA-Z0-9_][a-zA-Z0-9_-]*$");
}
public static void main(String[] args) throws JSONException {
String s = "[]";
JSONArray o = new JSONArray(s);
boolean valid = isValid(o);
System.out.println(valid);
}
}