From 5aaa749907ecfd54026219c8702d48f69ce23cb1 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 17 Sep 2020 18:06:18 -0700 Subject: [PATCH] DirtyDataMap implements Map --- .../datatypes/dirtydata/DirtyDataMap.java | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/datatypes/dirtydata/DirtyDataMap.java b/src/main/java/com/gmail/nossr50/datatypes/dirtydata/DirtyDataMap.java index ff2f64bbd..ada25a90a 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/dirtydata/DirtyDataMap.java +++ b/src/main/java/com/gmail/nossr50/datatypes/dirtydata/DirtyDataMap.java @@ -11,7 +11,7 @@ import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Function; -public class DirtyDataMap { +public class DirtyDataMap implements Map { private final @NotNull MutableBoolean dirtyFlag; //Can be pointed at a reference private @NotNull Map dataMap; @@ -41,7 +41,8 @@ public class DirtyDataMap { /* Map Interface Delegates */ - public V get(K key) { + @Override + public V get(Object key) { return dataMap.get(key); } @@ -53,11 +54,13 @@ public class DirtyDataMap { return dataMap.isEmpty(); } - public boolean containsKey(K key) { + @Override + public boolean containsKey(Object key) { return dataMap.containsKey(key); } - public boolean containsValue(V value) { + @Override + public boolean containsValue(Object value) { return dataMap.containsValue(value); } @@ -66,7 +69,7 @@ public class DirtyDataMap { return dataMap.put(key, value); } - public V remove(K key) { + public V remove(Object key) { setDirty(); return dataMap.remove(key); } @@ -81,67 +84,84 @@ public class DirtyDataMap { dataMap.clear(); } - public Set keySet() { + @Override + public @NotNull Set keySet() { setDirty(); return dataMap.keySet(); } - public Collection values() { + @Override + public @NotNull Collection values() { setDirty(); return dataMap.values(); } - public Set> entrySet() { + @Override + public @NotNull Set> entrySet() { setDirty(); return dataMap.entrySet(); } - public V getOrDefault(K key, V defaultValue) { + @Override + public V getOrDefault(Object key, V defaultValue) { return dataMap.getOrDefault(key, defaultValue); } + @Override public void forEach(BiConsumer action) { setDirty(); dataMap.forEach(action); } + @Override public void replaceAll(BiFunction function) { setDirty(); dataMap.replaceAll(function); } + @Override public V putIfAbsent(K key, V value) { setDirty(); return dataMap.putIfAbsent(key, value); } - public boolean remove(K key, V value) { + @Override + public boolean remove(Object key, Object value) { setDirty(); return dataMap.remove(key, value); } + @Override public boolean replace(K key, V oldValue, V newValue) { setDirty(); return dataMap.replace(key, oldValue, newValue); } + @Override public V replace(K key, V value) { setDirty(); return dataMap.replace(key, value); } + @Override public V computeIfAbsent(K key, @NotNull Function mappingFunction) { + setDirty(); return dataMap.computeIfAbsent(key, mappingFunction); } + @Override public V computeIfPresent(K key, @NotNull BiFunction remappingFunction) { + setDirty(); return dataMap.computeIfPresent(key, remappingFunction); } + @Override public V compute(K key, @NotNull BiFunction remappingFunction) { + setDirty(); return dataMap.compute(key, remappingFunction); } + @Override public V merge(K key, @NotNull V value, @NotNull BiFunction remappingFunction) { setDirty(); return dataMap.merge(key, value, remappingFunction);