All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.icthh.xm.commons.request.internal.XmRequestContextData Maven / Gradle / Ivy

There is a newer version: 4.0.12
Show newest version
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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy