TimeUnitEnum.java 803 Bytes
package com.yohoufo.msg.constants;

import java.util.HashMap;
import java.util.Map;

/**
 * 时间单位,1:秒,2:分钟,3:小时,4:天,5:周,6:月,7:年
 * Created by chao.chen on 2018/12/5.
 */
public enum  TimeUnitEnum {
    SECOND((short)1),
    MIN((short)2),
    HOUR((short)3),
    DAY((short)4),
    WEEK((short)5),
    MONTH((short)6),
    YEAR((short)7);
    short code;

    TimeUnitEnum(short code) {
        this.code = code;
    }

    public short getCode() {
        return code;
    }

    private static Map<Short,TimeUnitEnum> cache;

    static {
        cache = new HashMap<>(values().length);
        for(TimeUnitEnum tu: values()){
            cache.put(tu.code, tu);
        }
    }

    public static TimeUnitEnum getByCode(Short code){
        return cache.get(code);
    }
}