Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] method improvement rationale #1757

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.gson.*;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.job.Configmap;
import org.apache.hertzbeat.common.entity.job.Metrics;
Expand Down Expand Up @@ -54,7 +56,7 @@ public class CollectUtil {
* @return match num
*/
public static int countMatchKeyword(String content, String keyword) {
if (content == null || "".equals(content) || keyword == null || "".equals(keyword.trim())) {
if (StringUtils.isAnyEmpty(content, keyword)) {
return 0;
}
try {
Expand All @@ -71,7 +73,7 @@ public static int countMatchKeyword(String content, String keyword) {
}

public static DoubleAndUnit extractDoubleAndUnitFromStr(String str) {
if (str == null || "".equals(str)) {
if (StringUtils.isEmpty(str)) {
return null;
}
DoubleAndUnit doubleAndUnit = new DoubleAndUnit();
Expand Down Expand Up @@ -151,7 +153,7 @@ public static int getTimeout(String timeout) {
* @return timeout
*/
public static int getTimeout(String timeout, int defaultTimeout) {
if (timeout == null || "".equals(timeout.trim())) {
if (StringUtils.isEmpty(timeout)) {
return defaultTimeout;
}
try {
Expand Down Expand Up @@ -309,7 +311,7 @@ public static JsonElement replaceSmilingPlaceholder(JsonElement jsonElement, Map
Map<String, String> map = JsonUtil.fromJson(jsonValue, typeReference);
if (map != null) {
map.forEach((name, value) -> {
if (name != null && !"".equals(name.trim())) {
if (StringUtils.isEmpty(name)) {
jsonObject.addProperty(name, value);
}
});
Expand Down Expand Up @@ -424,7 +426,7 @@ public static void replaceFieldsForPushStyleMonitor(Metrics metrics, Map<String,
* @return byte[]
*/
public static byte[] fromHexString(String hexString) {
if (null == hexString || "".equals(hexString.trim())) {
if (StringUtils.isEmpty(hexString)) {
return null;
}
byte[] bytes = new byte[hexString.length() / HEX_STR_WIDTH];
Expand Down
Loading