From 17f0dddf20488d0b5fb212da539845c79d43d609 Mon Sep 17 00:00:00 2001 From: Speiger Date: Thu, 16 Sep 2021 23:53:57 +0200 Subject: [PATCH] Refactor and New Features -Changed: Refactored some variable names because they got out of hand since they were handed for single cases instead of making actual specific rules. -Added: mapping functions (only to objects) are now accessible to primitive collections. -Added: Filter function for Iterables/Iterators. (Iterable implements them automatically) --- .../speiger/src/builder/GlobalVariables.java | 29 ++- .../templates/collections/Iterable.template | 83 ++++---- .../templates/collections/Iterator.template | 2 +- .../templates/lists/ArrayList.template | 2 +- .../templates/lists/ImmutableList.template | 2 +- .../templates/lists/LinkedList.template | 2 +- .../LinkedOpenCustomHashMap.template | 4 +- .../customHash/OpenCustomHashMap.template | 4 +- .../maps/impl/hash/LinkedOpenHashMap.template | 4 +- .../maps/impl/hash/OpenHashMap.template | 4 +- .../immutable/ImmutableOpenHashMap.template | 4 +- .../maps/impl/misc/ArrayMap.template | 6 +- .../templates/queues/ArrayFIFOQueue.template | 4 +- .../queues/ArrayPriorityQueue.template | 4 +- .../queues/HeapPriorityQueue.template | 4 +- .../templates/queues/PriorityQueue.template | 4 +- .../templates/sets/AVLTreeSet.template | 2 +- .../templates/sets/ArraySet.template | 2 +- .../sets/ImmutableOpenHashSet.template | 2 +- .../sets/LinkedOpenCustomHashSet.template | 2 +- .../templates/sets/LinkedOpenHashSet.template | 2 +- .../templates/sets/OpenCustomHashSet.template | 2 +- .../templates/sets/OpenHashSet.template | 2 +- .../templates/sets/RBTreeSet.template | 2 +- .../templates/utils/Iterables.template | 107 +++++++---- .../templates/utils/Iterators.template | 180 +++++++++++------- .../templates/utils/PriorityQueues.template | 2 +- 27 files changed, 281 insertions(+), 186 deletions(-) diff --git a/src/builder/java/speiger/src/builder/GlobalVariables.java b/src/builder/java/speiger/src/builder/GlobalVariables.java index 02ac9b91..b820921a 100644 --- a/src/builder/java/speiger/src/builder/GlobalVariables.java +++ b/src/builder/java/speiger/src/builder/GlobalVariables.java @@ -43,27 +43,42 @@ public class GlobalVariables addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue()); addSimpleMapper(" KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+">" : ""); - addSimpleMapper(" KEY_GENERIC_SPECIAL_TYPE", type.isObject() ? " " : ""); addSimpleMapper(" KEY_KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", "+type.getKeyType()+">" : ""); + addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+">" : ""); - addSimpleMapper(" VALUE_GENERIC_SPECIAL_TYPE", valueType.isObject() ? " " : ""); addSimpleMapper(" VALUE_VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : ""); - addSimpleMapper(" VALUE_VALUE_SPECIAL_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", E>" : ""); + addSimpleMapper(" KEY_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : "")); - addSimpleMapper(" KEY_SPECIAL_VALUE_GENERIC_TYPE", valueType.isObject() ? "" : ""); - addSimpleMapper(" KEY_VALUE_SPECIAL_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", E>" : ""); addSimpleMapper(" KEY_VALUE_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : "")); + addSimpleMapper(" NO_GENERIC_TYPE", type.isObject() ? "" : ""); addSimpleMapper(" NO_KV_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "" : "") : valueType.isObject() ? "" : ""); addSimpleMapper(" KEY_COMPAREABLE_TYPE", type.isObject() ? "<"+type.getKeyType()+" extends Comparable>" : ""); + addSimpleMapper(" KEY_SUPER_GENERIC_TYPE", type.isObject() ? "" : ""); addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "" : ""); addSimpleMapper(" KEY_VALUE_SUPER_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "" : "") : (valueType.isObject() ? "" : "")); + addSimpleMapper(" KEY_ENUM_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">, "+valueType.getValueType()+">" : "<"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">>") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : "")); addSimpleMapper(" KEY_VALUE_ENUM_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : "")); + + addInjectMapper(" KEY_SPECIAL_GENERIC_TYPE", type.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>"); + addInjectMapper(" VALUE_SPECIAL_GENERIC_TYPE", valueType.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>"); + addInjectMapper(" KSK_GENERIC_TYPE", type.isObject() ? "<%s, "+type.getKeyType()+">" : "<%s>").removeBraces().setBraceType("<>"); + addInjectMapper(" KKS_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", %s>" : "<%s>").removeBraces().setBraceType("<>"); + addArgumentMapper(" KSS_GENERIC_TYPE", type.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>"); + addInjectMapper(" VSV_GENERIC_TYPE", valueType.isObject() ? "<%s, "+valueType.getValueType()+">" : "<%s>").removeBraces().setBraceType("<>"); + addInjectMapper(" VVS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>").removeBraces().setBraceType("<>"); + addArgumentMapper(" VSS_GENERIC_TYPE", valueType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>"); addSimpleMapper(" GENERIC_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+">" : ""); - addSimpleMapper(" GENERIC_VALUE_BRACES", type.isObject() ? " <"+valueType.getValueType()+">" : ""); + addSimpleMapper(" GENERIC_VALUE_BRACES", valueType.isObject() ? " <"+valueType.getValueType()+">" : ""); + addInjectMapper(" GENERIC_SPECIAL_KEY_BRACES", type.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>"); + addInjectMapper(" GENERIC_SPECIAL_VALUE_BRACES", valueType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>"); + + addInjectMapper(" GENERIC_KEY_SPECIAL_BRACES", type.isObject() ? " <"+type.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>"); + addInjectMapper(" GENERIC_VALUE_SPECIAL_BRACES", valueType.isObject() ? " <"+valueType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>"); + addSimpleMapper(" GENERIC_KEY_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+", "+valueType.getValueType()+">" : " <"+type.getKeyType()+">") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : "")); addSimpleMapper(" COMPAREABLE_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+" extends Comparable>" : ""); addSimpleMapper("KV_BRACES", type.isObject() || valueType.isObject() ? "<>" : ""); @@ -191,6 +206,7 @@ public class GlobalVariables addClassMapper("ITERATOR", "Iterator"); addClassMapper("ITERABLE", "Iterable"); addClassMapper("COLLECTION", "Collection"); + addClassMapper("TO_OBJECT_FUNCTION", "2ObjectFunction"); addBiClassMapper("FUNCTION", "Function", "2"); addClassMapper("LIST_ITER", "ListIter"); addClassMapper("LIST", "List"); @@ -269,6 +285,7 @@ public class GlobalVariables addSimpleMapper("TEST_VALUE", type.isObject() ? "getBoolean" : "get"); addSimpleMapper("NEW_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getKeyType()+"Stream"); addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array"); + addSimpleMapper("[SPACE]", " "); return this; } 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 2d7e3eb1..2516d2a8 100644 --- a/src/builder/resources/speiger/assets/collections/templates/collections/Iterable.template +++ b/src/builder/resources/speiger/assets/collections/templates/collections/Iterable.template @@ -5,14 +5,14 @@ import java.util.Objects; import java.util.function.Consumer; import speiger.src.collections.PACKAGE.functions.CONSUMER; -#else -import java.util.function.Function; -import speiger.src.collections.PACKAGE.utils.ITERABLES; +import speiger.src.collections.objects.collections.ObjectIterable; #endif +import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION; import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR; import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; +import speiger.src.collections.PACKAGE.utils.ITERABLES; /** * A Type-Specific {@link Iterable} that reduces (un)boxing @@ -20,11 +20,11 @@ import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; */ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable { - /** - * Returns an iterator over elements of type {@code T}. - * - * @return an Iterator. - */ + /** + * Returns an iterator over elements of type {@code T}. + * + * @return an Iterator. + */ @Override ITERATOR KEY_GENERIC_TYPE iterator(); @@ -32,16 +32,16 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable /** * A Type Specific foreach function that reduces (un)boxing * - * @implSpec - *

The default implementation behaves as if: - *

{@code
-     *     iterator().forEachRemaining(action);
-     * }
- * - * @param action The action to be performed for each element - * @throws NullPointerException if the specified action is null - * @see Iterable#forEach(Consumer) - */ + * @implSpec + *

The default implementation behaves as if: + *

{@code
+	 *	iterator().forEachRemaining(action);
+	 * }
+ * + * @param action The action to be performed for each element + * @throws NullPointerException if the specified action is null + * @see Iterable#forEach(Consumer) + */ default void forEach(CONSUMER action) { Objects.requireNonNull(action); iterator().forEachRemaining(action); @@ -53,10 +53,10 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable */ @Deprecated @Override - default void forEach(Consumer action) { - Objects.requireNonNull(action); - iterator().forEachRemaining(action); - } + default void forEach(Consumer action) { + Objects.requireNonNull(action); + iterator().forEachRemaining(action); + } #endif /** @@ -66,7 +66,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable * @param the generic type of the Object * @throws java.lang.NullPointerException if the specified action is null */ - default void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + default void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); iterator().forEachRemaining(input, action); } @@ -78,39 +78,46 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable @Override default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createUnknownSplititerator(iterator(), 0); } -#if TYPE_OBJECT /** * A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else. - * @param map the mapping function - * @Type(E) + * @param mapper the mapping function + * @param The return type. * @return a new Iterable that returns the desired result */ - default ObjectIterable map(Function map) { - return ObjectIterables.map(this, map); + default ObjectIterable map(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE mapper) { + return ITERABLES.map(this, mapper); } /** * A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else. - * @param map the flatMapping function - * @Type(E) - * @Type(V) + * @param mapper the flatMapping function + * @param The return type supplier. + * @param The return type. * @return a new Iterable that returns the desired result */ - default > ObjectIterable flatMap(Function map) { - return ObjectIterables.flatMap(this, map); + default > ObjectIterable flatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE mapper) { + return ITERABLES.flatMap(this, mapper); } /** * A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else. - * @param map the flatMapping function - * @Type(E) + * @param mapper the flatMapping function + * @param The return type. * @return a new Iterable that returns the desired result */ - default ObjectIterable arrayflatMap(Function map) { - return ObjectIterables.arrayFlatMap(this, map); + default ObjectIterable arrayflatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE mapper) { + return ITERABLES.arrayFlatMap(this, mapper); + } + + /** + * A Helper function to reduce the usage of Streams and allows to filter out unwanted elements + * @param filter the elements that should be kept. + * @return a Iterable that filtered out all unwanted elements + */ + default ITERABLE KEY_GENERIC_TYPE filter(PREDICATE KEY_GENERIC_TYPE filter) { + return ITERABLES.filter(this, filter); } -#endif /** * Helper function to reduce stream usage that allows to filter for any matches. * @param filter that should be applied diff --git a/src/builder/resources/speiger/assets/collections/templates/collections/Iterator.template b/src/builder/resources/speiger/assets/collections/templates/collections/Iterator.template index f1b8dbaa..3cfbebc8 100644 --- a/src/builder/resources/speiger/assets/collections/templates/collections/Iterator.template +++ b/src/builder/resources/speiger/assets/collections/templates/collections/Iterator.template @@ -74,7 +74,7 @@ public interface ITERATOR KEY_GENERIC_TYPE extends Iterator * @param the generic type of the Object * @throws java.lang.NullPointerException if the specified action is null */ - default void forEachRemaining(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + default void forEachRemaining(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); while(hasNext()) { action.accept(NEXT(), input); } } 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 bf84eba5..27518d7c 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template @@ -591,7 +591,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); for(int i = 0;i void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); for(int i = 0,m=data.length;i void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) action.accept(entry.value, input); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template index 9e290d88..01611275 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template @@ -885,7 +885,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); if(size() <= 0) return; int index = firstIndex; @@ -1001,7 +1001,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M } @Override - public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VALUE_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE action) { Objects.requireNonNull(action); if(size() <= 0) return; int index = firstIndex; diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template index c5cccfef..6576b50a 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template @@ -949,7 +949,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); if(size() <= 0) return; if(containsNull) action.accept(keys[nullIndex], input); @@ -1045,7 +1045,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL } @Override - public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VALUE_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE action) { Objects.requireNonNull(action); if(size() <= 0) return; if(containsNull) action.accept(values[nullIndex], input); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template index 14d764c7..d64b91b5 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template @@ -862,7 +862,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); if(size() <= 0) return; int index = firstIndex; @@ -979,7 +979,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G } @Override - public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VALUE_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE action) { Objects.requireNonNull(action); if(size() <= 0) return; int index = firstIndex; diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template index d36e4ef9..18126ce3 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template @@ -909,7 +909,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); if(size() <= 0) return; if(containsNull) action.accept(keys[nullIndex], input); @@ -1005,7 +1005,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE } @Override - public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VALUE_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE action) { Objects.requireNonNull(action); if(size() <= 0) return; if(containsNull) action.accept(values[nullIndex], input); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/immutable/ImmutableOpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/immutable/ImmutableOpenHashMap.template index a676aef8..59aa4a90 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/immutable/ImmutableOpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/immutable/ImmutableOpenHashMap.template @@ -783,7 +783,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_ } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); if(size() <= 0) return; int index = firstIndex; @@ -897,7 +897,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_ } @Override - public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VALUE_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE action) { Objects.requireNonNull(action); if(size() <= 0) return; int index = firstIndex; diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template index cbb630ad..a75956c6 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template @@ -1296,7 +1296,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); if(size() <= 0) return; for(int i = 0;i void forEach(E input, VALUE_BI_OBJECT_CONSUMER VALUE_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE action) { Objects.requireNonNull(action); for(int i = 0;i void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); for(int i = 0;i void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); if(first == last) return; for(int i = 0,m=size();i KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) { if(input == null || input.length < size()) input = NEW_SPECIAL_KEY_ARRAY(size()); if (first <= last) System.arraycopy(array, first, input, 0, last - first); else { diff --git a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template index 0c7deec0..981519d9 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template @@ -262,7 +262,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); for(int i = 0,m=size;i KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) { if(input == null || input.length < size()) input = NEW_SPECIAL_KEY_ARRAY(size()); System.arraycopy(array, 0, input, 0, size()); return input; diff --git a/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template b/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template index 9f7357e5..800bf8d2 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template @@ -249,7 +249,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_ } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); for(int i = 0,m=size;i KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) { if(input == null || input.length < size()) input = NEW_SPECIAL_KEY_ARRAY(size()); System.arraycopy(array, 0, input, 0, size()); return input; 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 f347e7fd..7681e2ed 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template @@ -86,7 +86,7 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY * @Type(E) * @return the contents of the queue into a seperate array. */ - public default KEY_GENERIC_SPECIAL_TYPE KEY_SPECIAL_TYPE[] TO_ARRAY() { return TO_ARRAY(NEW_SPECIAL_KEY_ARRAY(size())); } + public default GENERIC_SPECIAL_KEY_BRACES KEY_SPECIAL_TYPE[] TO_ARRAY() { return TO_ARRAY(NEW_SPECIAL_KEY_ARRAY(size())); } /** * A method to drop the contents of the Queue without clearing the queue * @param input where the elements should be inserted to. If it does not fit then it creates a new appropiatly created array @@ -94,5 +94,5 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY * @return the contents of the queue into a seperate array. * @note if the Type is generic then a Object Array is created instead of a Type Array */ - public KEY_GENERIC_SPECIAL_TYPE KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input); + public GENERIC_SPECIAL_KEY_BRACES KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input); } \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template index cea16dee..1bc07182 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template @@ -304,7 +304,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) action.accept(entry.key, input); diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/ArraySet.template b/src/builder/resources/speiger/assets/collections/templates/sets/ArraySet.template index 13780e3c..e2cd6bb8 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/ArraySet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/ArraySet.template @@ -350,7 +350,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); for(int i = 0;i void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); int index = firstIndex; while(index != -1) { diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template index fa0f1b98..a95c18fa 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template @@ -534,7 +534,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); int index = firstIndex; while(index != -1) { diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template index ed91cd51..8655082f 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template @@ -389,7 +389,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); int index = firstIndex; while(index != -1) { 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 b031c5bc..0ac97391 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template @@ -468,7 +468,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); if(size() <= 0) return; if(containsNull) action.accept(keys[nullIndex], input); 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 d5205586..d0753eb7 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template @@ -337,7 +337,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); if(size() <= 0) return; if(containsNull) action.accept(keys[nullIndex], input); diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/RBTreeSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/RBTreeSet.template index 46bcaeeb..9fd8819f 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/RBTreeSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/RBTreeSet.template @@ -304,7 +304,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE } @Override - public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + public void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE action) { Objects.requireNonNull(action); for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) action.accept(entry.key, input); diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/Iterables.template b/src/builder/resources/speiger/assets/collections/templates/utils/Iterables.template index 5db07621..a912ea85 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/Iterables.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/Iterables.template @@ -1,41 +1,29 @@ package speiger.src.collections.PACKAGE.utils; -#if TYPE_OBJECT -import java.util.function.Function; import speiger.src.collections.PACKAGE.collections.ITERABLE; -import speiger.src.collections.PACKAGE.collections.ITERATOR; +#if !TYPE_OBJECT +import speiger.src.collections.objects.collections.ObjectIterable; +import speiger.src.collections.objects.collections.ObjectIterator; #endif +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION; +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; /** * A Helper class for Iterables */ public class ITERABLES { -#if TYPE_OBJECT /** * A Helper function that maps a Iterable into a new Type. * @param iterable the iterable that should be mapped * @param mapper the function that decides what the result turns into. * @Type(T) - * @Type(E) + * @param The return type. * @return a iterable that is mapped to a new result */ - public static ITERABLE map(ITERABLE iterable, Function mapper) { - return new MappedIterableBRACES(iterable, mapper); - } - - - /** - * A Helper function that flatMaps a Iterable into a new Type. - * @param iterable the iterable that should be flatMapped - * @param mapper the function that decides what the result turns into. - * @Type(T) - * @Type(V) - * @Type(E) - * @return a iterable that is flatMapped to a new result - */ - public static > ITERABLE flatMap(ITERABLE iterable, Function mapper) { - return new FlatMappedIterableBRACES(iterable, mapper); + public static GENERIC_KEY_SPECIAL_BRACES ObjectIterable map(ITERABLE KEY_GENERIC_TYPE iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE mapper) { + return new MappedIterable<>(iterable, mapper); } /** @@ -43,58 +31,97 @@ public class ITERABLES * @param iterable the iterable that should be flatMapped * @param mapper the function that decides what the result turns into. * @Type(T) - * @Type(E) + * @param The return type supplier. + * @param The return type. * @return a iterable that is flatMapped to a new result */ - public static ITERABLE arrayFlatMap(ITERABLE iterable, Function mapper) { - return new FlatMappedArrayIterableBRACES(iterable, mapper); + public static GENERIC_KEY_SPECIAL_BRACES> ObjectIterable flatMap(ITERABLE KEY_GENERIC_TYPE iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE mapper) { + return new FlatMappedIterable<>(iterable, mapper); } - private static class MappedIterable implements ITERABLE + /** + * A Helper function that flatMaps a Iterable into a new Type. + * @param iterable the iterable that should be flatMapped + * @param mapper the function that decides what the result turns into. + * @Type(T) + * @param The return type. + * @return a iterable that is flatMapped to a new result + */ + public static GENERIC_KEY_SPECIAL_BRACES ObjectIterable arrayFlatMap(ITERABLE KEY_GENERIC_TYPE iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE mapper) { + return new FlatMappedArrayIterable<>(iterable, mapper); + } + + /** + * A Helper function that filters out all desired elements + * @param iterable that should be filtered. + * @param filter the filter that decides that should be let through + * @Type(T) + * @return a filtered iterable + */ + public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE filter(ITERABLE KEY_GENERIC_TYPE iterable, PREDICATE KEY_GENERIC_TYPE filter) { + return new FilteredIterableBRACES(iterable, filter); + } + + private static class MappedIterable KSS_GENERIC_TYPE implements ObjectIterable { - ITERABLE iterable; - Function mapper; + ITERABLE KEY_SPECIAL_GENERIC_TYPE iterable; + TO_OBJECT_FUNCTION KSS_GENERIC_TYPE mapper; - MappedIterable(ITERABLE iterable, Function mapper) { + MappedIterable(ITERABLE KEY_SPECIAL_GENERIC_TYPE iterable, TO_OBJECT_FUNCTION KSS_GENERIC_TYPE mapper) { this.iterable = iterable; this.mapper = mapper; } - public ITERATOR iterator() { + public ObjectIterator iterator() { return ITERATORS.map(iterable.iterator(), mapper); } } - private static class FlatMappedIterable> implements ITERABLE + private static class FlatMappedIterable KSS_GENERIC_TYPE> implements ObjectIterable { - ITERABLE iterable; - Function mapper; + ITERABLE KEY_SPECIAL_GENERIC_TYPE iterable; + TO_OBJECT_FUNCTION KSS_GENERIC_TYPE mapper; - FlatMappedIterable(ITERABLE iterable, Function mapper) { + FlatMappedIterable(ITERABLE KEY_SPECIAL_GENERIC_TYPE iterable, TO_OBJECT_FUNCTION KSS_GENERIC_TYPE mapper) { this.iterable = iterable; this.mapper = mapper; } @Override - public ITERATOR iterator() { + public ObjectIterator iterator() { return ITERATORS.flatMap(iterable.iterator(), mapper); } } - private static class FlatMappedArrayIterable implements ITERABLE + private static class FlatMappedArrayIterable KSS_GENERIC_TYPE implements ObjectIterable { - ITERABLE iterable; - Function mapper; + ITERABLE KEY_SPECIAL_GENERIC_TYPE iterable; + TO_OBJECT_FUNCTION KSS_GENERIC_TYPE mapper; - FlatMappedArrayIterable(ITERABLE iterable, Function mapper) { + FlatMappedArrayIterable(ITERABLE KEY_SPECIAL_GENERIC_TYPE iterable, TO_OBJECT_FUNCTION KSS_GENERIC_TYPE mapper) { this.iterable = iterable; this.mapper = mapper; } @Override - public ITERATOR iterator() { + public ObjectIterator iterator() { return ITERATORS.arrayFlatMap(iterable.iterator(), mapper); } } -#endif + + private static class FilteredIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE + { + ITERABLE KEY_GENERIC_TYPE iterable; + PREDICATE KEY_GENERIC_TYPE filter; + + public FilteredIterable(ITERABLE KEY_GENERIC_TYPE iterable, PREDICATE KEY_GENERIC_TYPE filter) { + this.iterable = iterable; + this.filter = filter; + } + + @Override + public ITERATOR KEY_GENERIC_TYPE iterator() { + return ITERATORS.filter(iterable.iterator(), filter); + } + } } \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/Iterators.template b/src/builder/resources/speiger/assets/collections/templates/utils/Iterators.template index e085e7eb..b19ffc87 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/Iterators.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/Iterators.template @@ -2,11 +2,14 @@ package speiger.src.collections.PACKAGE.utils; import java.util.Iterator; import java.util.NoSuchElementException; -#if TYPE_OBJECT -import java.util.function.Function; -#endif import speiger.src.collections.PACKAGE.collections.ITERATOR; +#if !TYPE_OBJECT +import speiger.src.collections.objects.collections.ObjectIterator; +import speiger.src.collections.objects.utils.ObjectIterators; +#endif +import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION; +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; import speiger.src.collections.PACKAGE.lists.LIST; import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; @@ -86,17 +89,16 @@ public class ITERATORS return iterator instanceof UnmodifiableListIterator ? iterator : new UnmodifiableListIteratorBRACES(iterator); } -#if TYPE_OBJECT /** * A Helper function that maps a Iterator into a new Type. * @param iterator that should be mapped * @param mapper the function that decides what the result turns into. * @Type(T) - * @Type(E) + * @param The return type. * @return a iterator that is mapped to a new result */ - public static ITERATOR map(ITERATOR iterator, Function mapper) { - return new MappedIteratorBRACES(iterator, mapper); + public static GENERIC_KEY_SPECIAL_BRACES ObjectIterator map(ITERATOR KEY_GENERIC_TYPE iterator, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE mapper) { + return new MappedIterator<>(iterator, mapper); } /** @@ -104,12 +106,12 @@ public class ITERATORS * @param iterator that should be flatMapped * @param mapper the function that decides what the result turns into. * @Type(T) - * @Type(V) - * @Type(E) + * @param The return type supplier. + * @param The return type. * @return a iterator that is flatMapped to a new result */ - public static > ITERATOR flatMap(ITERATOR iterator, Function mapper) { - return new FlatMappedIteratorBRACES(iterator, mapper); + public static GENERIC_KEY_SPECIAL_BRACES> ObjectIterator flatMap(ITERATOR KEY_GENERIC_TYPE iterator, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE mapper) { + return new FlatMappedIterator<>(iterator, mapper); } /** @@ -117,14 +119,24 @@ public class ITERATORS * @param iterator that should be flatMapped * @param mapper the function that decides what the result turns into. * @Type(T) - * @Type(E) + * @param The return type. * @return a iterator that is flatMapped to a new result */ - public static ITERATOR arrayFlatMap(ITERATOR iterator, Function mapper) { - return new FlatMappedArrayIteratorBRACES(iterator, mapper); + public static GENERIC_KEY_SPECIAL_BRACES ObjectIterator arrayFlatMap(ITERATOR KEY_GENERIC_TYPE iterator, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE mapper) { + return new FlatMappedArrayIterator<>(iterator, mapper); + } + + /** + * A Helper function that filters out all desired elements + * @param iterator that should be filtered. + * @param filter the filter that decides that should be let through + * @Type(T) + * @return a filtered iterator + */ + public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE filter(ITERATOR KEY_GENERIC_TYPE iterator, PREDICATE KEY_GENERIC_TYPE filter) { + return new FilteredIteratorBRACES(iterator, filter); } -#endif /** * Helper function to convert a Object Iterator into a Primitive Iterator * @param iterator that should be converted to a unboxing iterator @@ -641,13 +653,12 @@ public class ITERATORS } } -#if TYPE_OBJECT - private static class MappedIterator implements ITERATOR + private static class MappedIterator KSS_GENERIC_TYPE implements ObjectIterator { - ITERATOR iterator; - Function mapper; + ITERATOR KEY_SPECIAL_GENERIC_TYPE iterator; + TO_OBJECT_FUNCTION KSS_GENERIC_TYPE mapper; - MappedIterator(ITERATOR iterator, Function mapper) { + MappedIterator(ITERATOR KEY_SPECIAL_GENERIC_TYPE iterator, TO_OBJECT_FUNCTION KSS_GENERIC_TYPE mapper) { this.iterator = iterator; this.mapper = mapper; } @@ -658,8 +669,8 @@ public class ITERATORS } @Override - public KEY_TYPE NEXT() { - return mapper.apply(iterator.NEXT()); + public T next() { + return mapper.GET_VALUE(iterator.NEXT()); } @Override @@ -668,14 +679,14 @@ public class ITERATORS } } - private static class FlatMappedIterator> implements ITERATOR + private static class FlatMappedIterator KSS_GENERIC_TYPE> implements ObjectIterator { - ITERATOR iterator; + ITERATOR KEY_SPECIAL_GENERIC_TYPE iterator; Iterator last = null; - Function mapper; + TO_OBJECT_FUNCTION KSS_GENERIC_TYPE mapper; boolean foundNext = false; - FlatMappedIterator(ITERATOR iterator, Function mapper) { + FlatMappedIterator(ITERATOR KEY_SPECIAL_GENERIC_TYPE iterator, TO_OBJECT_FUNCTION KSS_GENERIC_TYPE mapper) { this.iterator = iterator; this.mapper = mapper; } @@ -683,47 +694,9 @@ public class ITERATORS void compute() { if(foundNext) return; foundNext = true; - while(iterator.hasNext()) - { + while(iterator.hasNext()) { if(last != null && last.hasNext()) return; - last = mapper.apply(iterator.next()).iterator(); - } - } - - @Override - public boolean hasNext() { - compute(); - return last != null && last.hasNext(); - } - - @Override - public KEY_TYPE NEXT() { - if(!hasNext()) throw new IllegalStateException("End of Iterator"); - KEY_TYPE result = last.next(); - foundNext = false; - return result; - } - } - - private static class FlatMappedArrayIterator implements ITERATOR - { - ITERATOR iterator; - Iterator last = null; - Function mapper; - boolean foundNext = false; - - FlatMappedArrayIterator(ITERATOR iterator, Function mapper) { - this.iterator = iterator; - this.mapper = mapper; - } - - void compute() { - if(foundNext) return; - foundNext = true; - while(iterator.hasNext()) - { - if(last != null && last.hasNext()) return; - last = wrap(mapper.apply(iterator.next())); + last = mapper.GET_VALUE(iterator.NEXT()).iterator(); } } @@ -736,11 +709,82 @@ public class ITERATORS @Override public T next() { if(!hasNext()) throw new IllegalStateException("End of Iterator"); - KEY_TYPE result = last.next(); + T result = last.next(); foundNext = false; return result; } } -#endif + private static class FlatMappedArrayIterator KSS_GENERIC_TYPE implements ObjectIterator + { + ITERATOR KEY_SPECIAL_GENERIC_TYPE iterator; + Iterator last = null; + TO_OBJECT_FUNCTION KSS_GENERIC_TYPE mapper; + boolean foundNext = false; + + FlatMappedArrayIterator(ITERATOR KEY_SPECIAL_GENERIC_TYPE iterator, TO_OBJECT_FUNCTION KSS_GENERIC_TYPE mapper) { + this.iterator = iterator; + this.mapper = mapper; + } + + void compute() { + if(foundNext) return; + foundNext = true; + while(iterator.hasNext()) { + if(last != null && last.hasNext()) return; + last = ObjectIterators.wrap(mapper.GET_VALUE(iterator.NEXT())); + } + } + + @Override + public boolean hasNext() { + compute(); + return last != null && last.hasNext(); + } + + @Override + public T next() { + if(!hasNext()) throw new IllegalStateException("End of Iterator"); + T result = last.next(); + foundNext = false; + return result; + } + } + + private static class FilteredIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE + { + ITERATOR KEY_GENERIC_TYPE iterator; + PREDICATE KEY_GENERIC_TYPE filter; + KEY_TYPE lastFound; + boolean foundNext = false; + + public FilteredIterator(ITERATOR KEY_GENERIC_TYPE iterator, PREDICATE KEY_GENERIC_TYPE filter) { + this.iterator = iterator; + this.filter = filter; + } + + void compute() { + if(foundNext) return; + while(iterator.hasNext()) { + lastFound = iterator.NEXT(); + if(filter.TEST_VALUE(lastFound)) { + foundNext = true; + break; + } + } + } + + @Override + public boolean hasNext() { + compute(); + return foundNext; + } + + @Override + public KEY_TYPE NEXT() { + if(!hasNext()) throw new IllegalStateException("End of Iterator"); + foundNext = false; + return lastFound; + } + } } \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/PriorityQueues.template b/src/builder/resources/speiger/assets/collections/templates/utils/PriorityQueues.template index 27c051d7..6f806c7d 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/PriorityQueues.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/PriorityQueues.template @@ -99,7 +99,7 @@ public class PRIORITY_QUEUES @Override public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() { synchronized(mutex) { return queue.comparator(); } } @Override - public KEY_GENERIC_SPECIAL_TYPE KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) { synchronized(mutex) { return queue.TO_ARRAY(input); } } + public GENERIC_SPECIAL_KEY_BRACES KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) { synchronized(mutex) { return queue.TO_ARRAY(input); } } } /**