From a9bc6fdbba35d382301e25c96cade8f247ff46b0 Mon Sep 17 00:00:00 2001 From: aikai Date: Wed, 9 Apr 2025 11:04:43 +0800 Subject: [PATCH] =?UTF-8?q?refactor(mqtt):=20=E4=BC=98=E5=8C=96=20Position?= =?UTF-8?q?MapLineDTO=20=E4=B8=AD=E7=9A=84=E6=9C=9D=E5=90=91=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用列表和条件语句替换冗长的 if-else 结构 - 提高代码可读性和可维护性 -减少代码重复,易于未来的修改和扩展 --- .../mqtt/api/path/dto/PositionMapLineDTO.java | 66 +++++++------------ 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/yudao-module-mqtt/yudao-module-mqtt-api/src/main/java/cn/iocoder/yudao/module/mqtt/api/path/dto/PositionMapLineDTO.java b/yudao-module-mqtt/yudao-module-mqtt-api/src/main/java/cn/iocoder/yudao/module/mqtt/api/path/dto/PositionMapLineDTO.java index 56ffffc7b..c1df7f708 100644 --- a/yudao-module-mqtt/yudao-module-mqtt-api/src/main/java/cn/iocoder/yudao/module/mqtt/api/path/dto/PositionMapLineDTO.java +++ b/yudao-module-mqtt/yudao-module-mqtt-api/src/main/java/cn/iocoder/yudao/module/mqtt/api/path/dto/PositionMapLineDTO.java @@ -6,6 +6,9 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import java.util.Arrays; +import java.util.List; + @Data @Builder @NoArgsConstructor @@ -109,67 +112,46 @@ public class PositionMapLineDTO { private Integer ppToward; + private static final List ANTI_LIST = Arrays.asList(1, 3, 6); + private static final List WHATEVER_LIST = Arrays.asList(4, 7, 8); + /** * 双向车道 反向行走变更车头朝向 - * + *

* 车头朝向(0:正正 1:正反 2:反正 3:反反 4正随 5随正 6随反 7反随 8随随 * * @param toward * @return */ public Integer changeToward(Integer toward) { - if (toward == 0) { - return 0; - } else if (toward == 1) { - return 1; - } else if (toward == 2) { - return 0; - } else if (toward == 3) { - return 1; - } else if (toward == 4) { - return 2; - } else if (toward == 5) { - return 0; - } else if (toward == 6) { - return 1; - } else if (toward == 7) { - return 2; - } else if (toward == 8) { - return 2; - } else { - return 0; + int ppToward = 0; + if (ANTI_LIST.contains(toward)) { + ppToward = 1; + } else if (WHATEVER_LIST.contains(toward)) { + ppToward = 2; } + return ppToward; } + + private static final List FIRST_ANTI_LIST = Arrays.asList(2, 3, 7); + private static final List FIRST_WHATEVER_LIST = Arrays.asList(5, 6, 8); + /** * 双向车道 反向行走变更车头朝向 - * + *

* 车头朝向(0:正正 1:正反 2:反正 3:反反 4正随 5随正 6随反 7反随 8随随 * * @param toward * @return */ public Integer changeTowardFirst(Integer toward) { - if (toward == 0) { - return 0; - } else if (toward == 1) { - return 0; - } else if (toward == 2) { - return 1; - } else if (toward == 3) { - return 1; - } else if (toward == 4) { - return 0; - } else if (toward == 5) { - return 2; - } else if (toward == 6) { - return 2; - } else if (toward == 7) { - return 1; - } else if (toward == 8) { - return 2; - } else { - return 0; + int ppToward = 0; + if (FIRST_ANTI_LIST.contains(toward)) { + ppToward = 1; + } else if (FIRST_WHATEVER_LIST.contains(toward)) { + ppToward = 2; } + return ppToward; } }