Repository: cxf Updated Branches: refs/heads/master 811daf375 -> 156fd30dc
[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/156fd30d Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/156fd30d Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/156fd30d Branch: refs/heads/master Commit: 156fd30dcc8880969817473fe5fe027884988822 Parents: 811daf3 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:22:57 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/156fd30d/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 9a6b112..5a4a419 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/156fd30d/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()); + } + +}