Example usage for java.util WeakHashMap put

List of usage examples for java.util WeakHashMap put

Introduction

In this page you can find the example usage for java.util WeakHashMap put.

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this map.

Usage

From source file:org.cellprofiler.preferences.CellProfilerPreferences.java

/**
 * Lookup or create a CellProfilerPreferences node for a given path.
 * @param delegate//  w  w w. j  av a  2s .c o  m
 * @param map
 * @return
 */
static private CellProfilerPreferences retrieveNode(String path,
        WeakHashMap<String, CellProfilerPreferences> map) {
    synchronized (map) {
        CellProfilerPreferences result = map.get(path);
        if (result == null) {
            CellProfilerPreferences root = map.get("/");
            final Preferences delegate = root.delegate.node(path);
            final int lastSlash = path.lastIndexOf("/");
            CellProfilerPreferences parent = null;
            if (lastSlash == 0) {
                parent = root;
            } else {
                parent = retrieveNode(path.substring(0, lastSlash), map);
            }
            result = new CellProfilerPreferences(parent, delegate, map);
            map.put(path, result);
        }
        return result;
    }
}

From source file:org.compass.gps.device.hibernate.embedded.CompassEventListener.java

private CompassHolder getCompassHolder(Configuration cfg) {
    WeakHashMap<Configuration, CompassHolder> contextMap = contexts.get();
    if (contextMap == null) {
        contextMap = new WeakHashMap<Configuration, CompassHolder>(2);
        contexts.set(contextMap);// w  ww .j  a  va 2  s. c om
    }
    CompassHolder compassHolder = contextMap.get(cfg);
    if (compassHolder == null) {
        compassHolder = initCompassHolder(cfg);
        if (compassHolder != null) {
            if (log.isDebugEnabled()) {
                log.debug("Regsitering new Compass Holder [" + compassHolder + "]");
            }
            contextMap.put(cfg, compassHolder);
        }
    }
    return compassHolder;
}

From source file:org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils.java

private static void isSuccessorOf_addCache(Class<?> clazz, String requiredClass, IsSuccessorResult result) {
    WeakHashMap<Class<?>, IsSuccessorResult> classes = m_isSuccessorOfCache.get(requiredClass);
    if (classes == null) {
        classes = new WeakHashMap<Class<?>, IsSuccessorResult>();
        m_isSuccessorOfCache.put(requiredClass, classes);
    }/*from  ww  w  .  j a va 2s .co m*/
    classes.put(clazz, result);
}