ObjectUtils.java
3.07 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
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
package com.diligrp.assistant.shared.util;
import java.util.ArrayList;
import java.util.List;
/**
* 通用工具类
*/
public class ObjectUtils {
public static boolean equals(String str1, String str2) {
if (str1 == str2) {
return true;
} else if (str1 != null && str2 != null) {
if (str1.length() != str2.length()) {
return false;
} else if (str1 instanceof String && str2 instanceof String) {
return str1.equals(str2);
} else {
int length = str1.length();
for(int i = 0; i < length; ++i) {
if (str1.charAt(i) != str2.charAt(i)) {
return false;
}
}
return true;
}
} else {
return false;
}
}
public static boolean equals(Object object1, Object object2) {
if (object1 == object2) {
return true;
}
return object1 != null && object2 != null ? object1.equals(object2) : false;
}
public static String[] split(String str, char separator) {
if (str == null) {
return null;
} else {
int len = str.length();
if (len == 0) {
return new String[0];
} else {
int i = 0;
int start = 0;
boolean match = false;
boolean lastMatch = false;
boolean preserveAllTokens = false;
List<String> list = new ArrayList<String>();
while(true) {
while(i < len) {
if (str.charAt(i) == separator) {
if (match || preserveAllTokens) {
list.add(str.substring(start, i));
match = false;
lastMatch = true;
}
++i;
start = i;
} else {
lastMatch = false;
match = true;
++i;
}
}
if (match || preserveAllTokens && lastMatch) {
list.add(str.substring(start, i));
}
return (String[])list.toArray(new String[list.size()]);
}
}
}
}
public static boolean isEmpty(String str) {
return str == null || str.length() == 0;
}
public static boolean isNotEmpty(String str) {
return !isEmpty(str);
}
public static <T> boolean isEmpty(List<T> array) {
return array == null || array.isEmpty();
}
public static <T> boolean isNotEmpty(List<T> array) {
return array != null && !array.isEmpty();
}
public static String trimToEmpty(String str) {
return str == null ? "" : str.trim();
}
public static boolean isNull(Object obj) {
return null == obj;
}
}