| | |
| | | STATUS("status"), |
| | | CONTROL("control"), |
| | | PROGRESS("progress"), |
| | | LIVESTREAM("livestream"), |
| | | ALL("all"); |
| | | |
| | | private final String type; |
| | |
| | | return type; |
| | | } |
| | | |
| | | public static MessageType fromString(String type) { |
| | | public static boolean fromString(String type) { |
| | | // 遍历MessageType枚举的所有值 |
| | | for (MessageType messageType : MessageType.values()) { |
| | | // 如果当前枚举值的type属性与传入的type字符串忽略大小写相等 |
| | | if (messageType.type.equalsIgnoreCase(type)) { |
| | | return messageType; |
| | | // 返回当前枚举值 |
| | | //return messageType; |
| | | return true; |
| | | } |
| | | } |
| | | throw new IllegalArgumentException("Unknown message type: " + type); |
| | | // 如果遍历完所有枚举值都没有找到匹配的,则抛出异常 |
| | | //throw new IllegalArgumentException("Unknown message type: " + type); |
| | | return false; |
| | | } |
| | | |
| | | } |