You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2017/04/11 16:24:11 UTC

[2/2] cxf git commit: [CXF-5407] Implement a full remove method for CacheMap

[CXF-5407] Implement a full remove method for CacheMap


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e8ee2cc5
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e8ee2cc5
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e8ee2cc5

Branch: refs/heads/3.1.x-fixes
Commit: e8ee2cc5d2d530f38bbe29297015a67d3c97ecf5
Parents: f7407e1e
Author: Daniel Kulp <dk...@apache.org>
Authored: Tue Apr 11 12:22:57 2017 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Tue Apr 11 12:24:04 2017 -0400

----------------------------------------------------------------------
 .../org/apache/cxf/common/util/CacheMap.java    | 10 ++++
 .../apache/cxf/common/util/CacheMapTest.java    | 50 ++++++++++++++++++++
 2 files changed, 60 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/e8ee2cc5/core/src/main/java/org/apache/cxf/common/util/CacheMap.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/common/util/CacheMap.java b/core/src/main/java/org/apache/cxf/common/util/CacheMap.java
index 4f0a98c..15b6963 100644
--- a/core/src/main/java/org/apache/cxf/common/util/CacheMap.java
+++ b/core/src/main/java/org/apache/cxf/common/util/CacheMap.java
@@ -19,6 +19,7 @@
 package org.apache.cxf.common.util;
 
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.WeakHashMap;
@@ -119,7 +120,16 @@ public class CacheMap<K, V> implements Map<K, V> {
 
     public V remove(Object key) {
         V v = mainDataMap.remove(key);
+        Set<K> keys = new HashSet<>(extraKeyMap.keySet());
         V v2 = extraKeyMap.remove(key);
+        for (K nk : keys) {
+            if (key.equals(nk)) {
+                V v3 = extraKeyMap.remove(nk);
+                if (v2 == null) {
+                    v2 = v3;
+                }
+            }
+        }
         return v == null ? v2 : v;
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/e8ee2cc5/core/src/test/java/org/apache/cxf/common/util/CacheMapTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/cxf/common/util/CacheMapTest.java b/core/src/test/java/org/apache/cxf/common/util/CacheMapTest.java
new file mode 100644
index 0000000..cdec8e4
--- /dev/null
+++ b/core/src/test/java/org/apache/cxf/common/util/CacheMapTest.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.common.util;
+
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+/**
+ * 
+ */
+public class CacheMapTest {
+
+    @Test
+    public void testRemove() {
+        Map<Object, Object> definitions = new CacheMap<Object, Object>();
+        
+        Object putValue = new Object();
+        
+        String putKey = "test";
+        definitions.put(putKey, putValue);
+        
+        String removeKey = new String("test");
+        Object removeValue = definitions.remove(removeKey);
+        
+        Assert.assertEquals(putKey, removeKey);
+        Assert.assertEquals(putValue, removeValue);
+        Assert.assertTrue(definitions.isEmpty());
+    }
+
+}