From 531443531dccecf9b70aa7094aa8a5f19f485586 Mon Sep 17 00:00:00 2001 From: Speiger Date: Tue, 28 Sep 2021 12:06:51 +0200 Subject: [PATCH] New Features. -Added: Suppliers. -Added: ComputeIfAbsent but value generator is a supplier --- Changelog.md | 4 ++- README.md | 4 +++ .../speiger/src/builder/GlobalVariables.java | 3 +++ .../templates/functions/Supplier.template | 26 +++++++++++++++++++ .../maps/abstracts/AbstractMap.template | 15 +++++++++++ .../customHash/OpenCustomHashMap.template | 13 ++++++++++ .../maps/impl/hash/OpenHashMap.template | 15 ++++++++++- .../immutable/ImmutableOpenHashMap.template | 6 ++++- .../maps/impl/misc/ArrayMap.template | 15 ++++++++++- .../maps/impl/tree/AVLTreeMap.template | 13 ++++++++++ .../maps/impl/tree/RBTreeMap.template | 13 ++++++++++ .../templates/maps/interfaces/Map.template | 9 +++++++ 12 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 src/builder/resources/speiger/assets/collections/templates/functions/Supplier.template diff --git a/Changelog.md b/Changelog.md index d2411775..be5ff279 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,9 +1,11 @@ # Changelog of versions -###Version 0.4.1 +### Version 0.4.1 - Changed: ForEach with input now provides input, value instead of value, input, this improves the usage of method references greatly - Added: addAll with Array-types in collections. - Added: Java Iterator/Iterable support for Stream replacing methods +- Added: Suppliers. +- Added: ComputeIfAbsent but value generator is a supplier ### Version 0.4.0 - Changed: Iterable specific helper functions were moved out of Iterators and moved into Iterables diff --git a/README.md b/README.md index 1832b6f6..d07bb371 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ But its focus is a different one. - SplitIterators - Iterators - Pairs +- Unary/Functions +- Suppliers +- Bi/Consumers ## Specialized Functions New Specialized functions that were added to increase performance or reduce allocations or Quality Of life. @@ -43,6 +46,7 @@ To highlight things that may be wanted. - addToAll: Same as addTo but bulkVersion. - removeOrDefault: removes a Element and if not present returns the default value instead of the present value. - mergeAll: BulkVersion of Merge function. + - computeIfAbsent: A Supplier based generator that covers a lot more reference method cases - Sorted Map: - addAndMoveToFirst/Last (From FastUtil but moved to Interface): Allows to add a element to the first/last position of a sorted Map. - moveToFirst/Last: Moves the desired element at the first/last position of the Map. diff --git a/src/builder/java/speiger/src/builder/GlobalVariables.java b/src/builder/java/speiger/src/builder/GlobalVariables.java index f5105551..f0adad82 100644 --- a/src/builder/java/speiger/src/builder/GlobalVariables.java +++ b/src/builder/java/speiger/src/builder/GlobalVariables.java @@ -147,6 +147,7 @@ public class GlobalVariables { addSimpleMapper("JAVA_PREDICATE", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getFileType()+"Predicate"); addSimpleMapper("JAVA_CONSUMER", type.isPrimitiveBlocking() ? "" : "java.util.function."+type.getCustomJDKType().getFileType()+"Consumer"); + addSimpleMapper("JAVA_SUPPLIER", type.isPrimitiveBlocking() ? "" : "java.util.function."+type.getCustomJDKType().getFileType()+"Supplier"); addSimpleMapper("JAVA_FUNCTION", type.getFunctionClass(valueType)); addSimpleMapper("JAVA_BINARY_OPERATOR", type == ClassType.BOOLEAN ? "" : (type.isObject() ? "java.util.function.BinaryOperator" : "java.util.function."+type.getCustomJDKType().getFileType()+"BinaryOperator")); addSimpleMapper("JAVA_UNARY_OPERATOR", type.isObject() ? "BinaryOperator" : type == ClassType.BOOLEAN ? "" : type.getCustomJDKType().getFileType()+"UnaryOperator"); @@ -225,6 +226,7 @@ public class GlobalVariables addClassMapper("SET", "Set"); addClassMapper("STRATEGY", "Strategy"); addClassMapper("STACK", "Stack"); + addClassMapper("SUPPLIER", "Supplier"); addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", ""); if(type.isObject()) { @@ -275,6 +277,7 @@ public class GlobalVariables addFunctionMapper("GET_KEY", "get"); if(type.isObject()) addFunctionValueMapper("GET_VALUE", valueType.isObject() ? "getObject" : "get"); else addSimpleMapper("GET_VALUE", "get"); + addSimpleMapper("GET_JAVA", type.isObject() ? "get" : "getAs"+type.getCustomJDKType().getNonFileType()); addFunctionMapper("LAST_KEY", "last"); addFunctionValueMapper("MERGE", "merge"); addFunctionMapper("NEXT", "next"); diff --git a/src/builder/resources/speiger/assets/collections/templates/functions/Supplier.template b/src/builder/resources/speiger/assets/collections/templates/functions/Supplier.template new file mode 100644 index 00000000..38856bb2 --- /dev/null +++ b/src/builder/resources/speiger/assets/collections/templates/functions/Supplier.template @@ -0,0 +1,26 @@ +package speiger.src.collections.PACKAGE.functions; + +/** + * Type-Specific Supplier interface that reduces (un)boxing and allows to merge other consumer types into this interface + * @Type(T) + */ +#if TYPE_OBJECT +public interface SUPPLIER KEY_GENERIC_TYPE extends java.util.function.Supplier +#else if JDK_TYPE && !TYPE_BOOLEAN +public interface SUPPLIER KEY_GENERIC_TYPE extends JAVA_SUPPLIER +#else +public interface SUPPLIER KEY_GENERIC_TYPE +#endif +{ + /** + * @return the supplied value + */ + public KEY_TYPE GET_KEY(); +#if JDK_TYPE && PRIMITIVE + + @Override + public default KEY_TYPE GET_JAVA() { + return GET_KEY(); + } +#endif +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/abstracts/AbstractMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/abstracts/AbstractMap.template index 897a9319..c4bf3291 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/abstracts/AbstractMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/abstracts/AbstractMap.template @@ -18,6 +18,7 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION; import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR; import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR; #endif +import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER; #if !TYPE_OBJECT && !VALUE_OBJECT import speiger.src.collections.objects.collections.ObjectIterator; #endif @@ -189,6 +190,20 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap