From d6d2c0a3964549d0b76f10ec84d81cba12344e36 Mon Sep 17 00:00:00 2001 From: Speiger Date: Thu, 15 Dec 2022 16:07:44 +0100 Subject: [PATCH] Changed that function names are closer to javas names. --- Changelog.md | 1 + .../src/builder/modules/FunctionModule.java | 18 +++++++++++++++++- .../templates/collections/Collection.template | 4 ++-- .../templates/collections/Iterable.template | 4 ++-- .../templates/lists/LinkedList.template | 8 +++++--- .../templates/queues/PriorityQueue.template | 5 ++--- .../templates/utils/Arrays.template | 6 +++--- 7 files changed, 32 insertions(+), 14 deletions(-) diff --git a/Changelog.md b/Changelog.md index 7824cf99..c727874d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ - Removed: BooleanSet and Maps that start with a Boolean classes since they can not be used anyways. - Breaking Change: Function classes now use the "apply/applyAs/test" format from Java itself, instead of the "get" format. This cleans up a lot of things. But will break existing function class implementations - Breaking Change: Classes that used PrimitiveCollection functions now default to java functions where applicable, this is to increase compat. +- Breaking Change: Some function classes now get closer to javas terms. (Predicate/UnaryOperator etc) ### Version 0.7.0 - Added: Over 11 Million Unit Tests to this library to ensure quality. diff --git a/src/builder/java/speiger/src/builder/modules/FunctionModule.java b/src/builder/java/speiger/src/builder/modules/FunctionModule.java index 3d70cf15..7ddc456a 100644 --- a/src/builder/java/speiger/src/builder/modules/FunctionModule.java +++ b/src/builder/java/speiger/src/builder/modules/FunctionModule.java @@ -34,6 +34,18 @@ public class FunctionModule extends BaseModule addRequirement("Function", "%1$s", RequiredType.BI_CLASS); addRemapper("Function", (keyType.isObject() ? "" : "%s")+"Predicate"); } + else if(keyType.isObject() && !valueType.isObject()) { + addRequirement("Function", "%2$s", RequiredType.BI_CLASS); + addRemapper("Function", "To%sFunction"); + } + else if(keyType == valueType) { + addRequirement("Function", "%1$s", RequiredType.BI_CLASS); + addRemapper("Function", (keyType.isObject() ? "" : "%s")+"UnaryOperator"); + } + else if(valueType.isObject()) { + addRequirement("Function", "%1$s", RequiredType.BI_CLASS); + addRemapper("Function", "%sFunction"); + } else addBiRequirement("Function"); addRemapper("BiConsumer", "%sConsumer"); } @@ -51,8 +63,12 @@ public class FunctionModule extends BaseModule addBiClassMapper("BI_CONSUMER", "Consumer", ""); addClassMapper("BI_TO_OBJECT_CONSUMER", "ObjectConsumer"); addAbstractMapper("BI_FROM_OBJECT_CONSUMER", "Object%sConsumer"); - addClassMapper("TO_OBJECT_FUNCTION", "2ObjectFunction"); + if(keyType.isObject()) addFunctionMappers("TO_OBJECT_FUNCTION", "UnaryOperator"); + else addClassMapper("TO_OBJECT_FUNCTION", "Function"); if(valueType == ClassType.BOOLEAN) addFunctionMappers("FUNCTION", "%sPredicate"); + else if(keyType.isObject() && !valueType.isObject()) addFunctionValueMappers("FUNCTION", "To%sFunction"); + else if(keyType == valueType) addFunctionMappers("FUNCTION", "%sUnaryOperator"); + else if(valueType.isObject()) addFunctionMappers("FUNCTION", "%sFunction"); else addBiClassMapper("FUNCTION", "Function", "2"); addFunctionMappers("PREDICATE", "%sPredicate"); diff --git a/src/builder/resources/speiger/assets/collections/templates/collections/Collection.template b/src/builder/resources/speiger/assets/collections/templates/collections/Collection.template index efcbf6b8..d248ec0c 100644 --- a/src/builder/resources/speiger/assets/collections/templates/collections/Collection.template +++ b/src/builder/resources/speiger/assets/collections/templates/collections/Collection.template @@ -12,7 +12,7 @@ import java.util.stream.StreamSupport; #endif #if TYPE_OBJECT import java.util.function.Consumer; -import speiger.src.collections.ints.functions.function.Int2ObjectFunction; +import java.util.function.IntFunction; #else import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif @@ -182,7 +182,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection, ITE * @return an array containing all of the elements in this collection * @see Collection#toArray(Object[]) */ - default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction action) { + default KEY_TYPE[] TO_ARRAY(IntFunction action) { return TO_ARRAY(action.apply(size())); } diff --git a/src/builder/resources/speiger/assets/collections/templates/collections/Iterable.template b/src/builder/resources/speiger/assets/collections/templates/collections/Iterable.template index fca6c797..4ecd8201 100644 --- a/src/builder/resources/speiger/assets/collections/templates/collections/Iterable.template +++ b/src/builder/resources/speiger/assets/collections/templates/collections/Iterable.template @@ -13,8 +13,8 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.objects.collections.ObjectIterable; #else import java.util.function.BiFunction; +import java.util.function.IntFunction; import java.util.Comparator; -import speiger.src.collections.ints.functions.function.Int2ObjectFunction; #endif import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION; @@ -288,7 +288,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable * @param action is the creator function of said Array to ensure type is kept. * @return a new Array of all elements */ - default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction action) { + default KEY_TYPE[] TO_ARRAY(IntFunction action) { ISizeProvider prov = ISizeProvider.of(this); if(prov != null) { int size = prov.size(); diff --git a/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template b/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template index fdfb2208..30d9c7a4 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template @@ -4,6 +4,7 @@ package speiger.src.collections.PACKAGE.lists; #if DEQUEUE_FEATURE import java.util.Comparator; #endif + import java.util.function.BiFunction; #else if PRIMITIVES import java.nio.JAVA_BUFFER; @@ -18,6 +19,9 @@ import java.util.Spliterator.JAVA_SPLIT_ITERATOR; #endif import java.util.function.Consumer; import java.util.function.Predicate; +#if TYPE_OBJECT +import java.util.function.IntFunction; +#endif #if !TYPE_OBJECT && JDK_FUNCTION import java.util.function.PREDICATE; #endif @@ -36,8 +40,6 @@ import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.collections.COLLECTION; #if !TYPE_OBJECT import speiger.src.collections.PACKAGE.collections.STACK; -#else -import speiger.src.collections.ints.functions.function.Int2ObjectFunction; #endif import speiger.src.collections.PACKAGE.collections.ITERATOR; #if DEQUEUE_FEATURE @@ -990,7 +992,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE #else @Override - public T[] toArray(Int2ObjectFunction action) { + public T[] toArray(IntFunction action) { return super.toArray(action); } diff --git a/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template b/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template index 0dedc38d..d2e92ae6 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template @@ -4,8 +4,7 @@ package speiger.src.collections.PACKAGE.queues; import java.util.Comparator; import java.util.Collection; import java.util.Iterator; - -import speiger.src.collections.ints.functions.function.Int2ObjectFunction; +import java.util.function.IntFunction; #else import speiger.src.collections.PACKAGE.functions.COMPARATOR; #endif @@ -189,7 +188,7 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY * @return an array containing all of the elements in this collection * @see Collection#toArray(Object[]) */ - default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction action) { + default KEY_TYPE[] TO_ARRAY(IntFunction action) { return TO_ARRAY(action.apply(size())); } #endif diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/Arrays.template b/src/builder/resources/speiger/assets/collections/templates/utils/Arrays.template index 68065f4e..5104c76e 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/Arrays.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/Arrays.template @@ -8,8 +8,8 @@ import java.util.concurrent.RecursiveAction; import speiger.src.collections.PACKAGE.functions.COMPARATOR; #else import java.util.Comparator; +import java.util.function.IntFunction; -import speiger.src.collections.ints.functions.function.Int2ObjectFunction; #endif import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.utils.ITERATORS; @@ -146,7 +146,7 @@ public class ARRAYS * @param action that is creating the Array to be poured into * @return array with all elements of the iterator */ - public static GENERIC_KEY_BRACES KEY_TYPE[] pour(ITERATOR KEY_GENERIC_TYPE iter, Int2ObjectFunction action) { + public static GENERIC_KEY_BRACES KEY_TYPE[] pour(ITERATOR KEY_GENERIC_TYPE iter, IntFunction action) { return pour(iter, Integer.MAX_VALUE, action); } @@ -158,7 +158,7 @@ public class ARRAYS * @ArrayType(T) * @return array with all requested elements of the iterator */ - public static GENERIC_KEY_BRACES KEY_TYPE[] pour(ITERATOR KEY_GENERIC_TYPE iter, int max, Int2ObjectFunction action) { + public static GENERIC_KEY_BRACES KEY_TYPE[] pour(ITERATOR KEY_GENERIC_TYPE iter, int max, IntFunction action) { COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE list = COLLECTIONS.wrapper(); ITERATORS.pour(iter, list, max); return list.TO_ARRAY(action.apply(list.size()));