VehicleEnum.java 976 Bytes
package com.dituhui.pea.enums;

import cn.hutool.core.util.ObjectUtil;

import java.util.Objects;


/**
 * 交通工具:1汽车;2电动车;3自行车;4步行 默认是汽车
 *
 * @author RenPing
 * @date 2023/10/24
 */
public enum VehicleEnum {
    CAR(1, "驾车"),
    ELECTRIC_CAR(2, "电动车"),
    BICYCLE(3, "骑行"),
    WALK(4, "步行");

    private Integer code;
    private String name;

    private VehicleEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static String getNameByValue(Integer value) {
        if (Objects.isNull(value)) {
            return null;
        }

        for (VehicleEnum enums : VehicleEnum.values()) {
            if (ObjectUtil.equal(enums.getCode(), value)) {
                return enums.getName();
            }
        }

        return null;
    }
}