@@ -0,0 +1,2296 @@
+package hudson.util;%0A%0Aimport java.util.Collection;%0Aimport java.util.Collections;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.Set;%0A%0A/**%0A * %7B@link Map%7D that has copy-on-write semantics, backed by %7B@link HashMap%7D.%0A *%0A * %3Cp%3E%0A * This class is suitable where highly concurrent access is needed, yet%0A * the write operation is relatively uncommon.%0A *%0A * @author Kohsuke Kawaguchi%0A */%0Apublic class CopyOnWriteHashMap%3CK,V%3E implements Map%3CK,V%3E %7B%0A    private volatile Map%3CK,V%3E core;%0A    /**%0A     * Read-only view of %7B@link #core%7D.%0A     */%0A    private volatile Map%3CK,V%3E view;%0A%0A    public CopyOnWriteHashMap(Map%3CK, V%3E core) %7B%0A        update(new HashMap%3CK,V%3E(core));%0A    %7D%0A%0A    public CopyOnWriteHashMap() %7B%0A        update(Collections.%3CK,V%3EemptyMap());%0A    %7D%0A%0A    private void update(Map%3CK, V%3E m) %7B%0A        core = m;%0A        view = Collections.unmodifiableMap(core);%0A    %7D%0A%0A    public int size() %7B%0A        return core.size();%0A    %7D%0A%0A    public boolean isEmpty() %7B%0A        return core.isEmpty();%0A    %7D%0A%0A    public boolean containsKey(Object key) %7B%0A        return core.containsKey(key);%0A    %7D%0A%0A    public boolean containsValue(Object value) %7B%0A        return core.containsValue(value);%0A    %7D%0A%0A    public V get(Object key) %7B%0A        return core.get(key);%0A    %7D%0A%0A    public synchronized V put(K key, V value) %7B%0A        Map%3CK,V%3E m = new HashMap%3CK,V%3E(core);%0A        V r = m.put(key,value);%0A        update(m);%0A%0A        return r;%0A    %7D%0A%0A    public synchronized V remove(Object key) %7B%0A        Map%3CK,V%3E m = new HashMap%3CK,V%3E(core);%0A        V r = m.remove(key);%0A        update(m);%0A%0A        return r;%0A    %7D%0A%0A    public synchronized void putAll(Map%3C? extends K, ? extends V%3E t) %7B%0A        Map%3CK,V%3E m = new HashMap%3CK,V%3E(core);%0A        m.putAll(t);%0A        update(m);%0A    %7D%0A%0A    public synchronized void clear() %7B%0A        update(Collections.%3CK,V%3EemptyMap());%0A    %7D%0A%0A    /**%0A     * This method will return a read-only %7B@link Set%7D.%0A     */%0A    public Set%3CK%3E keySet() %7B%0A        return view.keySet();%0A    %7D%0A%0A    /**%0A     * This method will return a read-only %7B@link Collection%7D.%0A     */%0A    public Collection%3CV%3E values() %7B%0A        return view.values();%0A    %7D%0A%0A    /**%0A     * This method will return a read-only %7B@link Set%7D.%0A     */%0A    public Set%3CEntry%3CK,V%3E%3E entrySet() %7B%0A        return view.entrySet();%0A    %7D%0A%7D%0A

implemented a copy-on-write map.