[jboss-remoting-commits] JBoss Remoting SVN: r5577 - remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Mon Nov 2 17:18:11 EST 2009


Author: david.lloyd at jboss.com
Date: 2009-11-02 17:18:11 -0500 (Mon, 02 Nov 2009)
New Revision: 5577

Modified:
   remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/CopyOnWriteHashMap.java
Log:
Add missing atomic putAll()

Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/CopyOnWriteHashMap.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/CopyOnWriteHashMap.java	2009-11-02 22:05:58 UTC (rev 5576)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/CopyOnWriteHashMap.java	2009-11-02 22:18:11 UTC (rev 5577)
@@ -201,7 +201,27 @@
         return identity ? new IdentityHashMap<K,V>(map) : new HashMap<K, V>(map);
     }
 
-    public void putAll(final Map<? extends K, ? extends V> m) {
+    public void putAll(final Map<? extends K, ? extends V> orig) {
+        if (orig == null) {
+            throw new NullPointerException("map is null");
+        }
+        if (orig.isEmpty()) {
+            return;
+        }
+        synchronized (writeLock) {
+            final Map<K, V> copy = copy(map);
+            for (Entry<? extends K, ? extends V> entry : orig.entrySet()) {
+                copy.put(entry.getKey(), entry.getValue());
+            }
+            if (copy.isEmpty()) {
+                map = emptyMap();
+            } else if (copy.size() == 1) {
+                final Entry<K, V> entry = copy.entrySet().iterator().next();
+                map = singletonMap(entry.getKey(), entry.getValue());
+            } else {
+                map = copy;
+            }
+        }
     }
 
     public void clear() {



More information about the jboss-remoting-commits mailing list