17
17
* author: Blankj
18
18
* blog : http://blankj.com
19
19
* time : 2017/12/24
20
- * desc : 对象相关工具类
20
+ * desc : utils about object
21
21
* </pre>
22
22
*/
23
23
public final class ObjectUtils {
@@ -27,10 +27,10 @@ private ObjectUtils() {
27
27
}
28
28
29
29
/**
30
- * 判断对象是否为空
30
+ * Return whether object is empty.
31
31
*
32
- * @param obj 对象
33
- * @return {@code true}: 为空 <br>{@code false}: 不为空
32
+ * @param obj The object.
33
+ * @return {@code true}: yes <br>{@code false}: no
34
34
*/
35
35
public static boolean isEmpty (final Object obj ) {
36
36
if (obj == null ) {
@@ -78,63 +78,64 @@ public static boolean isEmpty(final Object obj) {
78
78
}
79
79
80
80
/**
81
- * 判断对象是否非空
81
+ * Return whether object is not empty.
82
82
*
83
- * @param obj 对象
84
- * @return {@code true}: 非空 <br>{@code false}: 空
83
+ * @param obj The object.
84
+ * @return {@code true}: yes <br>{@code false}: no
85
85
*/
86
86
public static boolean isNotEmpty (final Object obj ) {
87
87
return !isEmpty (obj );
88
88
}
89
89
90
90
/**
91
- * 判断对象是否相等
91
+ * Return whether object1 is equals to object2.
92
92
*
93
- * @param o1 对象1
94
- * @param o2 对象2
95
- * @return {@code true}: 相等 <br>{@code false}: 不相等
93
+ * @param o1 The first object.
94
+ * @param o2 The second object.
95
+ * @return {@code true}: yes <br>{@code false}: no
96
96
*/
97
- public static boolean equals (Object o1 , Object o2 ) {
97
+ public static boolean equals (final Object o1 , final Object o2 ) {
98
98
return o1 == o2 || (o1 != null && o1 .equals (o2 ));
99
99
}
100
100
101
101
/**
102
- * 检查对象非空
102
+ * Require the object is not null.
103
103
*
104
- * @param object 对象
105
- * @param message 报错
106
- * @param <T> 范型
107
- * @return 非空对象
104
+ * @param <T> The value type.
105
+ * @param object The object.
106
+ * @param message The message to use with the NullPointerException.
107
+ * @return the object
108
+ * @throws NullPointerException if object is null
108
109
*/
109
- public static <T > T requireNonNull (T object , String message ) {
110
+ public static <T > T requireNonNull (final T object , final String message ) {
110
111
if (object == null ) {
111
112
throw new NullPointerException (message );
112
113
}
113
114
return object ;
114
115
}
115
116
116
117
/**
117
- * 获取非空或默认对象
118
+ * Return the nonnull object or default object.
118
119
*
119
- * @param object 对象
120
- * @param defaultObject 默认值
121
- * @param <T> 范型
122
- * @return 非空或默认对象
120
+ * @param <T> The value type.
121
+ * @param object The object.
122
+ * @param defaultObject The default object to use with the object is null.
123
+ * @return the nonnull object or default object
123
124
*/
124
- public static <T > T getOrDefault (T object , T defaultObject ) {
125
+ public static <T > T getOrDefault (final T object , final T defaultObject ) {
125
126
if (object == null ) {
126
127
return defaultObject ;
127
128
}
128
129
return object ;
129
130
}
130
131
131
132
/**
132
- * 获取对象哈希值
133
+ * Return the hash code of object.
133
134
*
134
- * @param o 对象
135
- * @return 哈希值
135
+ * @param o The object.
136
+ * @return the hash code of object
136
137
*/
137
- public static int hashCode (Object o ) {
138
+ public static int hashCode (final Object o ) {
138
139
return o != null ? o .hashCode () : 0 ;
139
140
}
140
141
}
0 commit comments