From c1862e6b051d61b6dd56f7c4d737633d03b87539 Mon Sep 17 00:00:00 2001 From: Speiger Date: Fri, 3 Jun 2022 14:38:56 +0200 Subject: [PATCH] Fixed a Few bugs with wrappers. -Fixed: Maps.EmptyMap getOrDefault wasn't returning the default value. -Fixed: Maps.UnmodifiableMap wasn't respecting the change of the DefaultReturnValue. (it has its own version of it so it doesn't break the rule of it, it wasn't returning the expected value. -Added: A bunch of Methods for Unmodifiable/Empty maps that should fail right out but would still make it past a certain point. (Compute/Merge/Supply/etc) --- .../templates/utils/maps/Maps.template | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/maps/Maps.template b/src/builder/resources/speiger/assets/collections/templates/utils/maps/Maps.template index a2ab0fd7..73e1078e 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/maps/Maps.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/maps/Maps.template @@ -318,6 +318,18 @@ public class MAPS @Override public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return EQUALS_KEY_TYPE(key, this.key) ? value : defaultValue; } #endif + @Override + public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); } + @Override + public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); } @Override public SingletonMap KEY_VALUE_GENERIC_TYPE copy() { return new SingletonMapKV_BRACES(key, value); } @Override @@ -366,8 +378,20 @@ public class MAPS public VALUE_TYPE GET_VALUE(KEY_TYPE key) { return getDefaultReturnValue(); } #if !TYPE_OBJECT || !VALUE_OBJECT @Override - public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return EMPTY_VALUE; } + public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return defaultValue; } #endif + @Override + public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); } + @Override + public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); } @Override public SET KEY_GENERIC_TYPE keySet() { return SETS.empty(); } @Override @@ -585,7 +609,7 @@ public class MAPS @Override public VALUE_TYPE GET_VALUE(KEY_TYPE key) { VALUE_TYPE type = map.GET_VALUE(key); - return VALUE_EQUALS(type, map.getDefaultReturnValue()) ? getDefaultReturnValue() : type; + return VALUE_EQUALS(type, map.getDefaultReturnValue()) && !map.containsKey(key) ? getDefaultReturnValue() : type; } #if !TYPE_OBJECT || !VALUE_OBJECT @Override @@ -605,6 +629,8 @@ public class MAPS public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); } @Override public MAP KEY_VALUE_GENERIC_TYPE copy() { return map.copy(); } + @Override + public void clear() { throw new UnsupportedOperationException(); } @Override public SET KEY_GENERIC_TYPE keySet() { @@ -687,7 +713,7 @@ public class MAPS @Override public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { synchronized(mutex) { return map.firstEntry(); } } @Override - public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { synchronized(mutex) { return map.firstEntry(); } } + public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { synchronized(mutex) { return map.lastEntry(); } } @Override public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { synchronized(mutex) { return map.pollFirstEntry(); } } @Override