This is an automated email from the ASF dual-hosted git repository.
jinrongtong pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new 22a7ec6b63 [ISSUE #6333] Simplify the logic of the
FilterAPI#buildSubscriptionData method (#6334)
22a7ec6b63 is described below
commit 22a7ec6b6324fab470fd4a42e7858a048dadee15
Author: mxsm <[email protected]>
AuthorDate: Tue Mar 14 11:23:51 2023 +0800
[ISSUE #6333] Simplify the logic of the FilterAPI#buildSubscriptionData
method (#6334)
---
.../remoting/protocol/filter/FilterAPI.java | 48 +++++++---------------
1 file changed, 15 insertions(+), 33 deletions(-)
diff --git
a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/filter/FilterAPI.java
b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/filter/FilterAPI.java
index bc05aaca76..10a6bb4633 100644
---
a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/filter/FilterAPI.java
+++
b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/filter/FilterAPI.java
@@ -16,49 +16,31 @@
*/
package org.apache.rocketmq.remoting.protocol.filter;
-import java.net.URL;
+import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.common.filter.ExpressionType;
import org.apache.rocketmq.remoting.protocol.heartbeat.SubscriptionData;
-public class FilterAPI {
- public static URL classFile(final String className) {
- final String javaSource = simpleClassName(className) + ".java";
- URL url = FilterAPI.class.getClassLoader().getResource(javaSource);
- return url;
- }
-
- public static String simpleClassName(final String className) {
- String simple = className;
- int index = className.lastIndexOf(".");
- if (index >= 0) {
- simple = className.substring(index + 1);
- }
+import java.util.Arrays;
- return simple;
- }
+public class FilterAPI {
public static SubscriptionData buildSubscriptionData(String topic, String
subString) throws Exception {
- SubscriptionData subscriptionData = new SubscriptionData();
+ final SubscriptionData subscriptionData = new SubscriptionData();
subscriptionData.setTopic(topic);
subscriptionData.setSubString(subString);
- if (null == subString || subString.equals(SubscriptionData.SUB_ALL) ||
subString.length() == 0) {
+ if (StringUtils.isEmpty(subString) ||
subString.equals(SubscriptionData.SUB_ALL)) {
subscriptionData.setSubString(SubscriptionData.SUB_ALL);
+ return subscriptionData;
+ }
+ String[] tags = subString.split("\\|\\|");
+ if (tags.length > 0) {
+ Arrays.stream(tags).map(String::trim).filter(tag ->
!tag.isEmpty()).forEach(tag -> {
+ subscriptionData.getTagsSet().add(tag);
+ subscriptionData.getCodeSet().add(tag.hashCode());
+ });
} else {
- String[] tags = subString.split("\\|\\|");
- if (tags.length > 0) {
- for (String tag : tags) {
- if (tag.length() > 0) {
- String trimString = tag.trim();
- if (trimString.length() > 0) {
- subscriptionData.getTagsSet().add(trimString);
-
subscriptionData.getCodeSet().add(trimString.hashCode());
- }
- }
- }
- } else {
- throw new Exception("subString split error");
- }
+ throw new Exception("subString split error");
}
return subscriptionData;
@@ -70,7 +52,7 @@ public class FilterAPI {
return buildSubscriptionData(topic, subString);
}
- if (subString == null || subString.length() < 1) {
+ if (StringUtils.isEmpty(subString)) {
throw new IllegalArgumentException("Expression can't be null! " +
type);
}