YxAc commented on code in PR #89:
URL: https://github.com/apache/rocketmq-mqtt/pull/89#discussion_r862317815
##########
mqtt-common/src/main/java/org/apache/rocketmq/mqtt/common/util/NamespaceUtil.java:
##########
@@ -24,45 +24,35 @@ public class NamespaceUtil {
private static final int RESOURCE_LENGTH = 2;
public static final String MQ_DEFAULT_NAMESPACE_NAME = "DEFAULT_INSTANCE";
- public NamespaceUtil() {
- }
-
public static String encodeToNamespaceResource(String namespace, String
resource) {
- return resource != null && namespace != null ? StringUtils.join(new
String[]{namespace, "%", resource}) : resource;
+ return resource != null && namespace != null ?
StringUtils.join(namespace, NAMESPACE_SPLITER, resource) : resource;
}
public static String decodeOriginResource(String resource) {
- if (resource != null && resource.contains("%")) {
- int firstIndex = resource.indexOf("%");
+ if (resource != null && resource.contains(NAMESPACE_SPLITER)) {
+ int firstIndex = resource.indexOf(NAMESPACE_SPLITER);
return resource.substring(firstIndex + 1);
- } else {
- return resource;
}
+ return resource;
}
public static String decodeMqttNamespaceIdFromKey(String key) {
return decodeMqttNamespaceIdFromClientId(key);
}
public static String decodeMqttNamespaceIdFromClientId(String clientId) {
- if (clientId != null && clientId.contains("%")) {
- String mqttNamespaceId = clientId.split("%")[0];
- return mqttNamespaceId;
- } else {
- return null;
- }
+ return splitNamespaceStr(clientId);
}
public static String decodeStoreNamespaceIdFromTopic(String topic) {
- if (topic != null && topic.contains("%")) {
- String storeNamespaceId = topic.split("%")[0];
- return storeNamespaceId;
- } else {
- return null;
- }
+ return splitNamespaceStr(topic);
Review Comment:
encapsulate duplicate code block
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]