TimeUnitEnum.java
803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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);
}
}