Package org.jzonic.jlo

Source Code of org.jzonic.jlo.NDC

package org.jzonic.jlo;

import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;

/**
* User: Mecky
* Date: 19.07.2005
* Time: 16:15:14
*/
public class NDC {

    private static final ThreadLocal resources = new ThreadLocal();

    private NDC() {
    }

    public static void put(String key,Object obj) {
        Map map = (Map) resources.get();
        // if no map then create one
    if (map == null) {
      map = new HashMap();
      resources.set(map);                                  
    }
        map.put(key,obj);
    }

    public static Object get(String key) {
        Map map = (Map) resources.get();
    if (map == null) {
      return null;
    }
    return map.get(key);
    }
 
  public void remove(String key) {
    Map map = (Map) resources.get();
    if (map != null) {
      if ( map.containsKey(key)) {
        map.remove(key);
      }
    }
  }

    public static String getAsString() {
        Map map = (Map) resources.get();
    if (map == null) {
      return null;
    }
        StringBuffer buffer = new StringBuffer();
        buffer.append("[");
        Iterator it = map.keySet().iterator();
        while ( it.hasNext() ) {
            String key = (String)it.next();
            if ( buffer.length() > 1 ) {
                buffer.append(",");
            }
            buffer.append(key);
            buffer.append("=");
            buffer.append(map.get(key).toString());
        }
        buffer.append("]");
        return buffer.toString();
    }

}
TOP

Related Classes of org.jzonic.jlo.NDC

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.