枚举常用方法

public enum ActionTypeEnum {

    //0开始1发送2特送3退回4取回5退件6转办7并行8包含9合流10办结取回…20结束;21发起督办22督办回复;31缓办32缓办恢复;41发起会签42会签办理;
    Start(0),
    Send(1),
    SpSend(2),
    Back(3),
    GetBack(4),
    Return(5),
    ChangeUser(6),
    //SplitAnd(7),
    //SplitOr(8),
    //Join(9),
    FinishedGetBack(10),
    EndCase(20),
    Supervise(21),
    SuperviseEnd(22),
    Stop(31),
    StopRecovery(32),
    Countersign(41),
    CountersignDoing(42);
    
    private Integer value;

    ActionTypeEnum(int value) {
        this.value = value;
    }

    public Integer getValue() {
        return value;
    }
}

根据value返回对应枚举类型

    public static ActionTypeEnum getActionType(Integer no) {
        for (ActionTypeEnum value : ActionTypeEnum.values()) {
            if (value.getValue().equals(no)) {
                return value;
            }
        }
        return null;
    }

根据value返回对应自定义的值

    public static String getText(Integer val){
        switch (val){
            case 0:
                return "开始";
            case 1:
                return "发送";
            case 2:
                return "特送";
            case 3:
                return "退回";
            case 4:
                return "取回";
            case 5:
                return "退件";
            case 6:
                return "转办";
            case 10:
                return "办结取回";
            case 20:
                return "结束";
            case 21:
                return "发起督办";
            case 22:
                return "督办回复";
            case 31:
                return "缓办";
            case 32:
                return "缓办恢复";
            case 41:
                return "发起会签";
            case 42:
                return "会签办理";
            default:
                return "无";
        }
    }

返回对应枚举的value与name

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 消息类型枚举
 * @author 梁伟浩
 * @date 2023/7/10 15:36
 * @study 星期一
 */
public enum MessageTypeEnum {

    TO_DO("待办业务"),

    TIME_WARNING("预警业务"),

    TIME_OUT("超时业务"),

    NODE_TIME_WARNING("节点预警业务"),

    NODE_TIME_OUT("节点超时业务"),

    SUPERVISE("督办业务"),

    BACK("退回业务"),

    CORRECTION("补正业务");

    private String messageType;

    MessageTypeEnum(String messageType) {
        this.messageType = messageType;
    }

    public String getMessageType() {
        return messageType;
    }
}


	//获取枚举list
    public List<MessageTypeDTO> getMessageTypeList() {
        List<MessageTypeEnum> messageTypeEnums = Arrays.asList(MessageTypeEnum.values());
        List<MessageTypeDTO> list = new ArrayList<>();
        messageTypeEnums.forEach(a-> {
            MessageTypeDTO messageTypeDTO = new MessageTypeDTO();
            messageTypeDTO.setName(a.name());
            messageTypeDTO.setValue(a.getMessageType());
            list.add(messageTypeDTO);
        });
        return list;
    }

你可能感兴趣的:(java)