TimeUnitEnum.java
1000 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
41
42
43
44
45
package com.yohoufo.msg.constants;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* 时间单位,1:秒,2:分钟,3:小时,4:天,5:周,6:月,7:年
* Created by chao.chen on 2018/12/5.
*/
public enum TimeUnitEnum {
SECOND((short)1, TimeUnit.SECONDS),
MIN((short)2, TimeUnit.MINUTES),
HOUR((short)3, TimeUnit.HOURS),
DAY((short)4, TimeUnit.DAYS);
short code;
private TimeUnit timeUnit;
TimeUnitEnum(short code, TimeUnit timeUnit) {
this.code = code;
this.timeUnit = timeUnit;
}
public TimeUnit getTimeUnit() {
return timeUnit;
}
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);
}
}