package com.mvc.service.aiiden;

import com.mvc.utils.NumberUtil;
import com.mvc.utils.StringUtil;

public enum UnitType {
    UNIT0(0, 0.0001),//因字轮表,添加 2023-07-15 guozhao
    UNIT1(1, 0.001),
    UNIT2(2, 0.01),
    UNIT3(3, 0.1),
    UNIT4(4, 1),
    UNIT5(5, 10),
    UNIT6(6, 100),
    UNIT7(7, 1000),
    UNIT8(8, 10000);

    private int key;
    private double value;

    public int getKey() {
        return key;
    }

    public void setKey(int key) {
        this.key = key;
    }

    public double getValue() {
        return value;
    }

    public void setValue(double value) {
        this.value = value;
    }

    UnitType(int key, double value) {
        this.key=key;
        this.value=value;
    }

    public static UnitType getElement(int key) {
        for (UnitType msg : UnitType.values()) {
            if (msg.key==key) {
                return msg;
            }
        }
        return null;
    }

    public static UnitType getElement(String key) {
        if(!NumberUtil.isNumberic(key)){
            return null;
        }
        int iKey = Integer.parseInt(key);
        for (UnitType msg : UnitType.values()) {
            if (msg.key==iKey) {
                return msg;
            }
        }
        return null;
    }

    public static UnitType getElement(double value) {
        for (UnitType msg : UnitType.values()) {
            if (msg.value==value) {
                return msg;
            }
        }
        return null;
    }
}
