diff --git a/Changelog.md b/Changelog.md index 7824cf9..c727874 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 3d70cf1..7ddc456 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 efcbf6b..d248ec0 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 fca6c79..4ecd820 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 fdfb220..30d9c7a 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 0dedc38..d2e92ae 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 68065f4..5104c76 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()));