diff --git a/NCPCommons/src/main/java/fr/neatmonster/nocheatplus/utilities/ds/LinkedHashMapCOW.java b/NCPCommons/src/main/java/fr/neatmonster/nocheatplus/utilities/ds/LinkedHashMapCOW.java index 7dec6ab7..e76beb31 100644 --- a/NCPCommons/src/main/java/fr/neatmonster/nocheatplus/utilities/ds/LinkedHashMapCOW.java +++ b/NCPCommons/src/main/java/fr/neatmonster/nocheatplus/utilities/ds/LinkedHashMapCOW.java @@ -110,7 +110,7 @@ public class LinkedHashMapCOW implements Map { } @Override - public V put(K key, V value) { + public V put(final K key, final V value) { final V out; synchronized (this) { final LinkedHashMap newMap = copyMap(); @@ -121,7 +121,7 @@ public class LinkedHashMapCOW implements Map { } @Override - public void putAll(Map m) { + public void putAll(final Map m) { synchronized (this) { final LinkedHashMap newMap = copyMap(); newMap.putAll(m); @@ -130,7 +130,7 @@ public class LinkedHashMapCOW implements Map { } @Override - public V remove(Object key) { + public V remove(final Object key) { final V out; synchronized (this) { final LinkedHashMap newMap = copyMap(); @@ -139,6 +139,23 @@ public class LinkedHashMapCOW implements Map { } return out; } + + /** + * Remove all given keys.
+ * Not the most efficient implementation, copying the map and then removing + * keys, but still better than iterating remove(key). + * + * @param keys + */ + public void removeAll(final Collection keys) { + synchronized (this) { + final LinkedHashMap newMap = copyMap(); + for (final K key : keys) { + newMap.remove(key); + } + this.map = newMap; + } + } @Override public int size() {