20
20
import com .fasterxml .jackson .core .type .TypeReference ;
21
21
import com .google .gson .*;
22
22
import lombok .extern .slf4j .Slf4j ;
23
+
24
+ import org .apache .commons .lang3 .StringUtils ;
23
25
import org .apache .hertzbeat .common .constants .CommonConstants ;
24
26
import org .apache .hertzbeat .common .entity .job .Configmap ;
25
27
import org .apache .hertzbeat .common .entity .job .Metrics ;
@@ -54,7 +56,7 @@ public class CollectUtil {
54
56
* @return match num
55
57
*/
56
58
public static int countMatchKeyword (String content , String keyword ) {
57
- if (content == null || "" . equals (content ) || keyword == null || "" . equals ( keyword . trim () )) {
59
+ if (StringUtils . isAnyEmpty (content , keyword )) {
58
60
return 0 ;
59
61
}
60
62
try {
@@ -71,7 +73,7 @@ public static int countMatchKeyword(String content, String keyword) {
71
73
}
72
74
73
75
public static DoubleAndUnit extractDoubleAndUnitFromStr (String str ) {
74
- if (str == null || "" . equals (str )) {
76
+ if (StringUtils . isEmpty (str )) {
75
77
return null ;
76
78
}
77
79
DoubleAndUnit doubleAndUnit = new DoubleAndUnit ();
@@ -151,7 +153,7 @@ public static int getTimeout(String timeout) {
151
153
* @return timeout
152
154
*/
153
155
public static int getTimeout (String timeout , int defaultTimeout ) {
154
- if (timeout == null || "" . equals (timeout . trim () )) {
156
+ if (StringUtils . isEmpty (timeout )) {
155
157
return defaultTimeout ;
156
158
}
157
159
try {
@@ -309,7 +311,7 @@ public static JsonElement replaceSmilingPlaceholder(JsonElement jsonElement, Map
309
311
Map <String , String > map = JsonUtil .fromJson (jsonValue , typeReference );
310
312
if (map != null ) {
311
313
map .forEach ((name , value ) -> {
312
- if (name != null && ! "" . equals (name . trim () )) {
314
+ if (! StringUtils . isEmpty (name )) {
313
315
jsonObject .addProperty (name , value );
314
316
}
315
317
});
@@ -424,7 +426,7 @@ public static void replaceFieldsForPushStyleMonitor(Metrics metrics, Map<String,
424
426
* @return byte[]
425
427
*/
426
428
public static byte [] fromHexString (String hexString ) {
427
- if (null == hexString || "" . equals (hexString . trim () )) {
429
+ if (StringUtils . isEmpty (hexString )) {
428
430
return null ;
429
431
}
430
432
byte [] bytes = new byte [hexString .length () / HEX_STR_WIDTH ];
0 commit comments