2 changed files with 69 additions and 1 deletions
@ -0,0 +1,62 @@ |
|||
package com.zc.business.enums; |
|||
|
|||
/** |
|||
* |
|||
*/ |
|||
public enum LaserMode { |
|||
LASER_OFF(0, "激光关闭"), |
|||
CONSTANT_ON(1, "常亮模式"), |
|||
BLINK_100MS(2, "间隔100ms闪烁模式"), |
|||
BLINK_200MS(3, "间隔200ms闪烁模式"), |
|||
BLINK_500MS(4, "间隔500ms闪烁模式"), |
|||
DOUBLE_BLINK(5, "2次闪烁模式"), |
|||
SOS(6, "SOS模式"), |
|||
CUSTOM_1(7, "自定义模式1"), |
|||
CUSTOM_2(8, "自定义模式2"), |
|||
CUSTOM_3(9, "自定义模式3"); |
|||
|
|||
private final int code; |
|||
private final String description; |
|||
|
|||
// 构造函数
|
|||
LaserMode(int code, String description) { |
|||
this.code = code; |
|||
this.description = description; |
|||
} |
|||
|
|||
// 获取 code
|
|||
public int getCode() { |
|||
return code; |
|||
} |
|||
|
|||
// 获取 description
|
|||
public String getDescription() { |
|||
return description; |
|||
} |
|||
|
|||
// 根据 code 获取对应的枚举值
|
|||
// 根据 code 获取对应的枚举值
|
|||
public static LaserMode getByCode(int code) { |
|||
for (LaserMode mode : values()) { |
|||
if (mode.getCode() == code) { |
|||
return mode; |
|||
} |
|||
} |
|||
throw new IllegalArgumentException("无效的模式代码: " + code); |
|||
} |
|||
// 根据名称获取对应的 code
|
|||
public static int getCodeByName(String name) { |
|||
for (LaserMode location : LaserMode.values()) { |
|||
if (location.getDescription().equals(name)) { |
|||
return location.getCode(); |
|||
} |
|||
} |
|||
throw new IllegalArgumentException("无效的: " + name); |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return String.format("%s (%d): %s", name(), code, description); |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue