ICommandType
package com.shenlan.robot.os.mqtt.commend.out;
/**
* @author liuxk
* @date 2020/10/14 17:06
*/
public interface ICommandType {
public Integer getCommand() ;
public String getName();
}
CommandType
package com.shenlan.robot.os.mqtt.commend.out;
/**
* 消息类型定义体
*/
public enum CommandType implements ICommandType {
/**
* 扫路王点云视频控制开关
*/
POINT_CLOUD_VIDEO_ACTION(1011,"扫路王点云视频控制开关");
private Integer command;
private String name;
CommandType(Integer cmd,String name) {
this.command = cmd;
this.name = name;
}
@Override
public Integer getCommand() {
return command;
}
@Override
public String getName(){
return name;
}
}
EnumUtil
package com.shenlan.robot.os.util;
import com.shenlan.robot.os.mqtt.commend.out.ICommandType;
/**
* @author liuxk
* @date 2020/10/14 17:14
*/
public class EnumUtil {
public static <T extends ICommandType> String getName(Integer command, Class<T> t){
for(T item: t.getEnumConstants()){
if(command.equals(item.getCommand())){
return item.getName();
}
}
return "";
}
public static <T extends ICommandType> Integer getCommand(String name, Class<T> t){
for(T item: t.getEnumConstants()){
if(item.getName().equals(name.trim())){
return item.getCommand();
}
}
return 1000;
}
}