EquipmentStatusEnum.java
2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.huaheng.control.management.dto;
/**
* 设备状态枚举类
* @author TanYibin
* @createDate 2026年1月13日
*/
public enum EquipmentStatusEnum {
/**
* 空闲
*/
FREE("FREE", "空闲"),
/**
* 运行中
*/
RUNNING("RUNNING", "运行中"),
/**
* 离线
*/
OFFLINE("OFFLINE", "离线"),
/**
* 异常
*/
EXCEPTION("EXCEPTION", "异常");
/**
* 枚举键值
*/
private final String key;
/**
* 枚举描述
*/
private final String description;
/**
* 构造函数
* @param key 枚举键值
* @param description 枚举描述
*/
EquipmentStatusEnum(String key, String description) {
this.key = key;
this.description = description;
}
/**
* 获取枚举键值
* @return 键值
*/
public String getKey() {
return key;
}
/**
* 获取枚举描述
* @return 描述信息
*/
public String getDescription() {
return description;
}
/**
* 根据键值获取枚举实例
* @param key 键值
* @return 对应的枚举实例
* @throws IllegalArgumentException 如果键值不存在
*/
public static EquipmentStatusEnum fromKey(String key) {
for (EquipmentStatusEnum status : EquipmentStatusEnum.values()) {
if (status.getKey().equals(key)) {
return status;
}
}
throw new IllegalArgumentException("无效的设备状态键值: " + key);
}
/**
* 检查键值是否存在
* @param key 键值
* @return 是否存在
*/
public static boolean containsKey(String key) {
for (EquipmentStatusEnum status : EquipmentStatusEnum.values()) {
if (status.getKey().equals(key)) {
return true;
}
}
return false;
}
/**
* 获取所有枚举值的键值数组
* @return 键值数组
*/
public static String[] keys() {
EquipmentStatusEnum[] statuses = values();
String[] keys = new String[statuses.length];
for (int i = 0; i < statuses.length; i++) {
keys[i] = statuses[i].getKey();
}
return keys;
}
@Override
public String toString() {
return key + ":" + description;
}
}