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

[ISSUE #6333]Simplify the logic of the FilterAPI#buildSubscriptionData method #6334

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Changes from all 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 @@ -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;
Expand All @@ -70,7 +52,7 @@ public static SubscriptionData build(final String topic, final String subString,
return buildSubscriptionData(topic, subString);
}

if (subString == null || subString.length() < 1) {
if (StringUtils.isEmpty(subString)) {
throw new IllegalArgumentException("Expression can't be null! " + type);
}

Expand Down