吉安感知网项目-后端
xiebin
2026-01-06 d207a86cdf1ab52ef8cb7cd83bad8fceab8038cf
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
46
47
48
49
50
51
52
package org.sxkj.common.utils;
 
 
 
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
 
/**
 * 全局数据存取
 */
public class GlobalTimeRecordUtils {
 
    private static ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap();
 
 
    /**
     * 时间赋值
     *
     * @param key
     */
    public static <T> void setTime(String key, T newValue) {
        Object oldValue = concurrentHashMap.get(key);
        if (Objects.nonNull(newValue) &&!newValue.equals(oldValue)) {
            concurrentHashMap.put(key, newValue);
        }
    }
 
    /**
     * 删除key
     * @param key
     * @param <T>
     */
    public static <T> void remove(String key) {
        concurrentHashMap.remove(key);
    }
 
    /**
     * 获取唯一数据
     *
     * @param key key 值
     * @param <T> 类型
     * @return 返回值
     */
    public static <T> T getTime(String key) {
        Object object = concurrentHashMap.get(key);
        if (Objects.nonNull(object)) {
            return (T) object;
        }
        return null;
    }
 
}