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;
|
}
|
|
}
|