From 5e67e45910a1e75780775242c91f412d8fc8783d Mon Sep 17 00:00:00 2001 From: Speiger Date: Tue, 6 Jun 2023 11:21:52 +0200 Subject: [PATCH] Fixed failing tests/errors --- Changelog.md | 1 - .../collections/templates/lists/ArrayList.template | 7 +++++++ .../collections/templates/lists/CopyOnWriteList.template | 6 ++++++ .../templates/sets/OpenCustomHashSet.template | 9 ++++++--- .../collections/templates/sets/OpenHashSet.template | 9 ++++++--- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Changelog.md b/Changelog.md index edabe6b..ba74fc6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,7 +7,6 @@ - Added: ComputeNonDefault functions which will contain the current behavior of the Compute function, while the Compute will be changed to be more java compliant! - Fixed: SetValue wasn't working on forEach implementations. - ### Version 0.8.0 - Added: getFirst/getLast/removeFirst/removeLast to Lists - Added: Dedicated implementations for toArray into TreeSets diff --git a/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template b/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template index afb705d..7659012 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template @@ -13,6 +13,7 @@ import java.util.function.Consumer; #endif import java.util.function.BiFunction; +import java.util.function.IntFunction; #endif #if !TYPE_OBJECT && JDK_FUNCTION import java.util.function.PREDICATE; @@ -1080,6 +1081,12 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE return a; } +#else + @Override + public E[] toArray(IntFunction action) { + return super.toArray(action); + } + #endif /** * A function to return the size of the list diff --git a/src/builder/resources/speiger/assets/collections/templates/lists/CopyOnWriteList.template b/src/builder/resources/speiger/assets/collections/templates/lists/CopyOnWriteList.template index 98026b3..c469a52 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/CopyOnWriteList.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/CopyOnWriteList.template @@ -13,6 +13,7 @@ import java.util.function.Consumer; import java.util.function.Supplier; #if TYPE_OBJECT import java.util.function.BiFunction; +import java.util.function.IntFunction; #endif #if !TYPE_OBJECT && JDK_FUNCTION import java.util.function.PREDICATE; @@ -1331,6 +1332,11 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER if (a.length > size) a[size] = EMPTY_KEY_VALUE; return a; } +#else + @Override + public E[] toArray(IntFunction action) { + return super.toArray(action); + } #endif diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template index 29975d2..13c069f 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template @@ -484,7 +484,8 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T @Override public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { if(a == null || a.length < size()) a = new KEY_TYPE[size()]; - for(int i = nullIndex-1, index = 0;i>=0;i--) { + if(containsNull) a[0] = EMPTY_KEY_VALUE; + for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) { if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) a[index++] = keys[i]; } if (a.length > size) a[size] = EMPTY_KEY_VALUE; @@ -497,7 +498,8 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T public Object[] toArray() { if(isEmpty()) return ObjectArrays.EMPTY_ARRAY; Object[] obj = new Object[size()]; - for(int i = nullIndex-1, index = 0;i>=0;i--) { + if(containsNull) obj[0] = KEY_TO_OBJ(EMPTY_KEY_VALUE); + for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) { if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) obj[index++] = KEY_TO_OBJ(keys[i]); } return obj; @@ -508,7 +510,8 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T public E[] toArray(E[] a) { if(a == null) a = (E[])new Object[size()]; else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size()); - for(int i = nullIndex-1, index = 0;i>=0;i--) { + if(containsNull) a[0] = (E)KEY_TO_OBJ(EMPTY_KEY_VALUE); + for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) { if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) a[index++] = (E)KEY_TO_OBJ(keys[i]); } if (a.length > size) a[size] = null; diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template index a6a3df3..d462181 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template @@ -374,7 +374,8 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp @Override public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { if(a == null || a.length < size()) a = new KEY_TYPE[size()]; - for(int i = nullIndex-1, index = 0;i>=0;i--) { + if(containsNull) a[0] = EMPTY_KEY_VALUE; + for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) { if(KEY_EQUALS_NOT_NULL(keys[i])) a[index++] = keys[i]; } if (a.length > size) a[size] = EMPTY_KEY_VALUE; @@ -387,7 +388,8 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp public Object[] toArray() { if(isEmpty()) return ObjectArrays.EMPTY_ARRAY; Object[] obj = new Object[size()]; - for(int i = nullIndex-1, index = 0;i>=0;i--) { + if(containsNull) obj[0] = KEY_TO_OBJ(EMPTY_KEY_VALUE); + for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) { if(KEY_EQUALS_NOT_NULL(keys[i])) obj[index++] = KEY_TO_OBJ(keys[i]); } return obj; @@ -398,7 +400,8 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp public E[] toArray(E[] a) { if(a == null) a = (E[])new Object[size()]; else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size()); - for(int i = nullIndex-1, index = 0;i>=0;i--) { + if(containsNull) a[0] = (E)KEY_TO_OBJ(EMPTY_KEY_VALUE); + for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) { if(KEY_EQUALS_NOT_NULL(keys[i])) a[index++] = (E)KEY_TO_OBJ(keys[i]); } if (a.length > size) a[size] = null;