mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-28 18:31:24 +01:00
Add removeAll.
Considering to use this map for otherwise fully synchronized maps, e.g. with the chat checks.
This commit is contained in:
parent
b6c146ce64
commit
bf0b515889
@ -110,7 +110,7 @@ public class LinkedHashMapCOW<K, V> implements Map<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public V put(K key, V value) {
|
public V put(final K key, final V value) {
|
||||||
final V out;
|
final V out;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
final LinkedHashMap<K, V> newMap = copyMap();
|
final LinkedHashMap<K, V> newMap = copyMap();
|
||||||
@ -121,7 +121,7 @@ public class LinkedHashMapCOW<K, V> implements Map<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putAll(Map<? extends K, ? extends V> m) {
|
public void putAll(final Map<? extends K, ? extends V> m) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
final LinkedHashMap<K, V> newMap = copyMap();
|
final LinkedHashMap<K, V> newMap = copyMap();
|
||||||
newMap.putAll(m);
|
newMap.putAll(m);
|
||||||
@ -130,7 +130,7 @@ public class LinkedHashMapCOW<K, V> implements Map<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public V remove(Object key) {
|
public V remove(final Object key) {
|
||||||
final V out;
|
final V out;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
final LinkedHashMap<K, V> newMap = copyMap();
|
final LinkedHashMap<K, V> newMap = copyMap();
|
||||||
@ -139,6 +139,23 @@ public class LinkedHashMapCOW<K, V> implements Map<K, V> {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all given keys.<br>
|
||||||
|
* 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<K> keys) {
|
||||||
|
synchronized (this) {
|
||||||
|
final LinkedHashMap<K, V> newMap = copyMap();
|
||||||
|
for (final K key : keys) {
|
||||||
|
newMap.remove(key);
|
||||||
|
}
|
||||||
|
this.map = newMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
|
Loading…
Reference in New Issue
Block a user