Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.LinkedHashMap;
import java.util.Map;

public class Main {
    private static ThreadLocal<Map> params = new ThreadLocal<Map>();

    /**
     * setting value to current ThreadLocal map.
     * @param name
     * @param value
     * @author <a href="mailto:iffiff1@gmail.com">Tyler Chen</a> 
     * @since Aug 18, 2015
     */
    public static void set(String name, Object value) {
        Map map = params.get();
        if (map == null) {
            map = new LinkedHashMap();
            params.set(map);
        }
        map.put(name, value);
    }

    /**
     * getting value from current ThreadLocal map.
     * @param name
     * @return
     * @author <a href="mailto:iffiff1@gmail.com">Tyler Chen</a> 
     * @since Aug 18, 2015
     */
    public static <T> T get(String name) {
        Map map = params.get();
        if (map == null) {
            return null;
        }
        return (T) map.get(name);
    }
}