Skip to content

Commit 7fe6d2d

Browse files
dukbongTJxiaobao
andauthored
[refactor] method improvement rationale (apache#1757)
Signed-off-by: Hyeon Sung <[email protected]> Co-authored-by: 铁甲小宝 <[email protected]>
1 parent ea7fd2b commit 7fe6d2d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

collector/src/main/java/org/apache/hertzbeat/collector/util/CollectUtil.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import com.fasterxml.jackson.core.type.TypeReference;
2121
import com.google.gson.*;
2222
import lombok.extern.slf4j.Slf4j;
23+
24+
import org.apache.commons.lang3.StringUtils;
2325
import org.apache.hertzbeat.common.constants.CommonConstants;
2426
import org.apache.hertzbeat.common.entity.job.Configmap;
2527
import org.apache.hertzbeat.common.entity.job.Metrics;
@@ -54,7 +56,7 @@ public class CollectUtil {
5456
* @return match num
5557
*/
5658
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)) {
5860
return 0;
5961
}
6062
try {
@@ -71,7 +73,7 @@ public static int countMatchKeyword(String content, String keyword) {
7173
}
7274

7375
public static DoubleAndUnit extractDoubleAndUnitFromStr(String str) {
74-
if (str == null || "".equals(str)) {
76+
if (StringUtils.isEmpty(str)) {
7577
return null;
7678
}
7779
DoubleAndUnit doubleAndUnit = new DoubleAndUnit();
@@ -151,7 +153,7 @@ public static int getTimeout(String timeout) {
151153
* @return timeout
152154
*/
153155
public static int getTimeout(String timeout, int defaultTimeout) {
154-
if (timeout == null || "".equals(timeout.trim())) {
156+
if (StringUtils.isEmpty(timeout)) {
155157
return defaultTimeout;
156158
}
157159
try {
@@ -309,7 +311,7 @@ public static JsonElement replaceSmilingPlaceholder(JsonElement jsonElement, Map
309311
Map<String, String> map = JsonUtil.fromJson(jsonValue, typeReference);
310312
if (map != null) {
311313
map.forEach((name, value) -> {
312-
if (name != null && !"".equals(name.trim())) {
314+
if (!StringUtils.isEmpty(name)) {
313315
jsonObject.addProperty(name, value);
314316
}
315317
});
@@ -424,7 +426,7 @@ public static void replaceFieldsForPushStyleMonitor(Metrics metrics, Map<String,
424426
* @return byte[]
425427
*/
426428
public static byte[] fromHexString(String hexString) {
427-
if (null == hexString || "".equals(hexString.trim())) {
429+
if (StringUtils.isEmpty(hexString)) {
428430
return null;
429431
}
430432
byte[] bytes = new byte[hexString.length() / HEX_STR_WIDTH];

0 commit comments

Comments
 (0)