Commit 08d57dab629b26db1cec85880aeb3198eabe4298
1 parent
084b73d2
```
feat(mqtt-core): 优化接收事件类型匹配逻辑 - 将ReceiveEventType枚举中的value字段重命名为code,提高语义清晰度 - 修改构造函数参数名从value改为code,保持命名一致性 - 将静态方法of重命名为fuzzyMatching,更准确地描述模糊匹配功能 - 更新matchEventType方法调用,使用新的fuzzyMatching方法 - 修改内部实现使用code字段进行主题匹配,提升代码可读性 ```
Showing
1 changed file
with
6 additions
and
6 deletions
mqtt-core/src/main/java/com/diligrp/mqtt/core/type/ReceiveEventType.java
| ... | ... | @@ -6,10 +6,10 @@ public enum ReceiveEventType { |
| 6 | 6 | PRINTER_RECEIPT_SERVICE("/printSucc/"), |
| 7 | 7 | PRINTER_ONLINE_SERVICE("/priGoOnline/"), |
| 8 | 8 | UNKNOWN_SERVICE("unknownService"); |
| 9 | - public final String value; | |
| 9 | + public final String code; | |
| 10 | 10 | |
| 11 | - ReceiveEventType(String value) { | |
| 12 | - this.value = value; | |
| 11 | + ReceiveEventType(String code) { | |
| 12 | + this.code = code; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | /** |
| ... | ... | @@ -20,7 +20,7 @@ public enum ReceiveEventType { |
| 20 | 20 | */ |
| 21 | 21 | public static ReceiveEventType matchEventType(String topic) { |
| 22 | 22 | return Optional.ofNullable(topic) |
| 23 | - .map(ReceiveEventType::of) | |
| 23 | + .map(ReceiveEventType::fuzzyMatching) | |
| 24 | 24 | .orElse(UNKNOWN_SERVICE); |
| 25 | 25 | } |
| 26 | 26 | |
| ... | ... | @@ -30,9 +30,9 @@ public enum ReceiveEventType { |
| 30 | 30 | * @param topic 主题 |
| 31 | 31 | * @return {@link ReceiveEventType } |
| 32 | 32 | */ |
| 33 | - public static ReceiveEventType of(String topic) { | |
| 33 | + public static ReceiveEventType fuzzyMatching(String topic) { | |
| 34 | 34 | for (ReceiveEventType eventType : ReceiveEventType.values()) { |
| 35 | - if (topic.startsWith(eventType.value)) { | |
| 35 | + if (topic.startsWith(eventType.code)) { | |
| 36 | 36 | return eventType; |
| 37 | 37 | } |
| 38 | 38 | } | ... | ... |