refactor: fix PushRetryStrategyEnum#parse(String), and some code style optimization of module common (#171)
diff --git a/adapter/storage/src/main/java/org/apache/rocketmq/eventbridge/adapter/storage/rocketmq/runtimer/PropertiesResolveService.java b/adapter/storage/src/main/java/org/apache/rocketmq/eventbridge/adapter/storage/rocketmq/runtimer/PropertiesResolveService.java
index 81e175b..4fd687d 100644
--- a/adapter/storage/src/main/java/org/apache/rocketmq/eventbridge/adapter/storage/rocketmq/runtimer/PropertiesResolveService.java
+++ b/adapter/storage/src/main/java/org/apache/rocketmq/eventbridge/adapter/storage/rocketmq/runtimer/PropertiesResolveService.java
@@ -37,8 +37,8 @@
}
public String getPropertiesValue(String name) {
- if (!name.contains(CommonConstants.V_PREFIXE)) {
- name = CommonConstants.V_PREFIXE + name + CommonConstants.V_POSTFIX;
+ if (!name.contains(CommonConstants.V_PREFIX)) {
+ name = CommonConstants.V_PREFIX + name + CommonConstants.V_POSTFIX;
}
return stringValueResolver.resolveStringValue(name);
}
diff --git a/common/src/main/java/org/apache/rocketmq/eventbridge/config/CommonConstants.java b/common/src/main/java/org/apache/rocketmq/eventbridge/config/CommonConstants.java
index b93eb4a..8fed32e 100644
--- a/common/src/main/java/org/apache/rocketmq/eventbridge/config/CommonConstants.java
+++ b/common/src/main/java/org/apache/rocketmq/eventbridge/config/CommonConstants.java
@@ -17,7 +17,7 @@
package org.apache.rocketmq.eventbridge.config;
public interface CommonConstants {
- String V_PREFIXE = "${";
+ String V_PREFIX = "${";
String V_POSTFIX = "}";
}
diff --git a/common/src/main/java/org/apache/rocketmq/eventbridge/enums/PushRetryStrategyEnum.java b/common/src/main/java/org/apache/rocketmq/eventbridge/enums/PushRetryStrategyEnum.java
index aae17c2..bf9431f 100644
--- a/common/src/main/java/org/apache/rocketmq/eventbridge/enums/PushRetryStrategyEnum.java
+++ b/common/src/main/java/org/apache/rocketmq/eventbridge/enums/PushRetryStrategyEnum.java
@@ -43,7 +43,7 @@
return BACKOFF_RETRY;
}
for (PushRetryStrategyEnum pushRetryStrategyEnum : PushRetryStrategyEnum.values()) {
- if (pushRetryStrategyEnum.equals(pushRetryStrategy)) {
+ if (pushRetryStrategyEnum.name().equals(pushRetryStrategy)) {
return pushRetryStrategyEnum;
}
}
diff --git a/common/src/main/java/org/apache/rocketmq/eventbridge/tools/pattern/PatternEvaluatorBuilder.java b/common/src/main/java/org/apache/rocketmq/eventbridge/tools/pattern/PatternEvaluatorBuilder.java
index 73c1501..f9e6d3e 100644
--- a/common/src/main/java/org/apache/rocketmq/eventbridge/tools/pattern/PatternEvaluatorBuilder.java
+++ b/common/src/main/java/org/apache/rocketmq/eventbridge/tools/pattern/PatternEvaluatorBuilder.java
@@ -131,7 +131,7 @@
PatternErrorMessages.INVALID_PATTERN_VALUE + element.getAsString());
}
- if (entries.size() == 0) {
+ if (entries.isEmpty()) {
throw new InvalidEventPatternException(PatternErrorMessages.NO_DATA_PATTERN_KEY);
}
}
@@ -173,7 +173,7 @@
}
private static PatternEntry parsePatternEntry(String ruleName, String rulePath, JsonArray jsonElements) {
- if (jsonElements.size() == 0) {
+ if (jsonElements.isEmpty()) {
// Empty array
throw new InvalidEventPatternException(
PatternErrorMessages.INVALID_PATTERN_VALUE + jsonElements.toString());
diff --git a/common/src/main/java/org/apache/rocketmq/eventbridge/tools/transform/JsonPathUtil.java b/common/src/main/java/org/apache/rocketmq/eventbridge/tools/transform/JsonPathUtil.java
index 25d6c42..2663742 100644
--- a/common/src/main/java/org/apache/rocketmq/eventbridge/tools/transform/JsonPathUtil.java
+++ b/common/src/main/java/org/apache/rocketmq/eventbridge/tools/transform/JsonPathUtil.java
@@ -83,7 +83,7 @@
if (!JsonPathUtil.isValidAndDefinite(jsonPath)) {
throw new EventBridgeException(TransformErrorCode.InvalidConfig, jsonPath);
}
- String subPath = jsonPath.substring(2, jsonPath.length());
+ String subPath = jsonPath.substring(2);
String[] paths = subPath.split(JSONPATH_SPLIT);
if (paths.length <= index) {
throw new EventBridgeException(TransformErrorCode.InvalidConfig, jsonPath);
@@ -101,14 +101,14 @@
if (!JsonPathUtil.isValidAndDefinite(jsonPath)) {
throw new EventBridgeException(TransformErrorCode.InvalidConfig, jsonPath);
}
- String subPath = jsonPath.substring(2, jsonPath.length());
+ String subPath = jsonPath.substring(2);
String[] paths = subPath.split(JSONPATH_SPLIT);
if (paths.length <= startIndex) {
throw new EventBridgeException(TransformErrorCode.InvalidConfig, jsonPath);
}
StringBuffer buffer = new StringBuffer("$");
for (; startIndex < paths.length; startIndex++) {
- buffer.append("." + paths[startIndex]);
+ buffer.append(".").append(paths[startIndex]);
}
return buffer.toString();
}
diff --git a/common/src/main/java/org/apache/rocketmq/eventbridge/tools/transform/StringSubstitutorTemplate.java b/common/src/main/java/org/apache/rocketmq/eventbridge/tools/transform/StringSubstitutorTemplate.java
index eb715ee..83f1156 100644
--- a/common/src/main/java/org/apache/rocketmq/eventbridge/tools/transform/StringSubstitutorTemplate.java
+++ b/common/src/main/java/org/apache/rocketmq/eventbridge/tools/transform/StringSubstitutorTemplate.java
@@ -62,7 +62,7 @@
log.debug("template: " + outputTemplate);
List<Map.Entry<String, JsonElement>> jsonTemplateEntryList = getAndCheckEmbedObject();
- if (jsonTemplateEntryList.size() > 0) {
+ if (!jsonTemplateEntryList.isEmpty()) {
for (Map.Entry<String, JsonElement> entry : jsonTemplateEntryList) {
String key = removeVariableMark(entry.getValue().getAsJsonObject().get(EB_SYS_EMBED_OBJECT).getAsString());
JsonObject embedJsonObject = entry.getValue().getAsJsonObject();