com.icthh.xm.commons.request.internal.XmRequestContextData Maven / Gradle / Ivy
package com.icthh.xm.commons.request.internal;
import java.util.HashMap;
import java.util.Map;
/**
* The {@link XmRequestContextData} class.
*/
class XmRequestContextData {
private static final ThreadLocal THREAD_LOCAL =
ThreadLocal.withInitial(XmRequestContextData::new);
static XmRequestContextData get() {
return THREAD_LOCAL.get();
}
void destroyCurrent() {
THREAD_LOCAL.remove();
}
private Map model = new HashMap<>();
boolean containsKey(String key) {
return model.containsKey(key);
}
T getValue(String key, Class type) {
return type.cast(model.get(key));
}
T getValueOrDefault(String key, Class type, T defaultValue) {
return type.cast(model.getOrDefault(key, defaultValue));
}
void putValue(String key, Object value) {
model.put(key, value);
}
}