diff --git a/src/builder/java/speiger/src/builder/GlobalVariables.java b/src/builder/java/speiger/src/builder/GlobalVariables.java index 300d33d1..02ac9b91 100644 --- a/src/builder/java/speiger/src/builder/GlobalVariables.java +++ b/src/builder/java/speiger/src/builder/GlobalVariables.java @@ -48,7 +48,10 @@ public class GlobalVariables 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() ? "" : ""); @@ -183,6 +186,7 @@ public class GlobalVariables addClassMapper("LIST_ITERATOR", "ListIterator"); addClassMapper("BI_ITERATOR", "BidirectionalIterator"); addBiClassMapper("BI_CONSUMER", "Consumer", ""); + addClassMapper("BI_OBJECT_CONSUMER", "ObjectConsumer"); addClassMapper("SPLIT_ITERATOR", "Splititerator"); addClassMapper("ITERATOR", "Iterator"); addClassMapper("ITERABLE", "Iterable"); @@ -204,17 +208,20 @@ public class GlobalVariables addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", ""); if(type.isObject()) { - if(!valueType.isObject()) - { - addSimpleMapper("VALUE_CONSUMER", valueType.getFileType()+"Consumer"); - } + if(!valueType.isObject()) addSimpleMapper("VALUE_CONSUMER", valueType.getFileType()+"Consumer"); + else addSimpleMapper("VALUE_CONSUMER", "Consumer"); addSimpleMapper("CONSUMER", "Consumer"); addSimpleMapper("COMPARATOR", "Comparator"); addSimpleMapper("IARRAY", "IObjectArray"); } else { - addClassMapper("CONSUMER", "Consumer"); + if(valueType.isObject()) + { + addSimpleMapper("VALUE_CONSUMER", "Consumer"); + addSimpleMapper("CONSUMER", type.getFileType()+"Consumer"); + } + else addClassMapper("CONSUMER", "Consumer"); addClassMapper("COMPARATOR", "Comparator"); addFunctionMappers("IARRAY", "I%sArray"); } @@ -258,6 +265,8 @@ public class GlobalVariables addFunctionValueMappers("REPLACE_VALUES", valueType.isObject() ? "replaceObjects" : "replace%ss"); addFunctionMappers("REPLACE", type.isObject() ? "replaceObjects" : "replace%ss"); addFunctionMappers("SORT", "sort%ss"); + addSimpleMapper("VALUE_TEST_VALUE", valueType.isObject() ? "getBoolean" : "get"); + addSimpleMapper("TEST_VALUE", type.isObject() ? "getBoolean" : "get"); addSimpleMapper("NEW_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getKeyType()+"Stream"); addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array"); 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 cc43712b..2d7e3eb1 100644 --- a/src/builder/resources/speiger/assets/collections/templates/collections/Iterable.template +++ b/src/builder/resources/speiger/assets/collections/templates/collections/Iterable.template @@ -1,7 +1,7 @@ package speiger.src.collections.PACKAGE.collections; -#if !TYPE_OBJECT import java.util.Objects; +#if !TYPE_OBJECT import java.util.function.Consumer; import speiger.src.collections.PACKAGE.functions.CONSUMER; @@ -9,6 +9,7 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER; import java.util.function.Function; import speiger.src.collections.PACKAGE.utils.ITERABLES; #endif +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; @@ -26,8 +27,8 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable */ @Override ITERATOR KEY_GENERIC_TYPE iterator(); -#if !TYPE_OBJECT +#if !TYPE_OBJECT /** * A Type Specific foreach function that reduces (un)boxing * @@ -56,7 +57,19 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable Objects.requireNonNull(action); iterator().forEachRemaining(action); } + #endif + /** + * Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner. + * @param input the object that should be included + * @param action The action to be performed for each element + * @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) { + Objects.requireNonNull(action); + iterator().forEachRemaining(input, action); + } /** * A Type Specific Type Splititerator to reduce boxing/unboxing @@ -72,7 +85,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable * @Type(E) * @return a new Iterable that returns the desired result */ - public default ObjectIterable map(Function map) { + default ObjectIterable map(Function map) { return ObjectIterables.map(this, map); } @@ -83,7 +96,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable * @Type(V) * @return a new Iterable that returns the desired result */ - public default > ObjectIterable flatMap(Function map) { + default > ObjectIterable flatMap(Function map) { return ObjectIterables.flatMap(this, map); } @@ -93,7 +106,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable * @Type(E) * @return a new Iterable that returns the desired result */ - public default ObjectIterable arrayflatMap(Function map) { + default ObjectIterable arrayflatMap(Function map) { return ObjectIterables.arrayFlatMap(this, map); } @@ -103,13 +116,10 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable * @param filter that should be applied * @return true if any matches were found */ - public default boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + default boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { -#if TYPE_OBJECT - if(filter.getBoolean(iter.NEXT())) return true; -#else - if(filter.GET_VALUE(iter.NEXT())) return true; -#endif + if(filter.TEST_VALUE(iter.NEXT())) return true; } return false; } @@ -119,13 +129,10 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable * @param filter that should be applied * @return true if no matches were found */ - public default boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + default boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { -#if TYPE_OBJECT - if(filter.getBoolean(iter.NEXT())) return false; -#else - if(filter.GET_VALUE(iter.NEXT())) return false; -#endif + if(filter.TEST_VALUE(iter.NEXT())) return false; } return true; } @@ -135,13 +142,10 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable * @param filter that should be applied * @return true if all matches. */ - public default boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + default boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { -#if TYPE_OBJECT - if(!filter.getBoolean(iter.NEXT())) return false; -#else - if(!filter.GET_VALUE(iter.NEXT())) return false; -#endif + if(!filter.TEST_VALUE(iter.NEXT())) return false; } return true; } @@ -151,14 +155,11 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable * @param filter that should be applied * @return the found value or the null equivalent variant. */ - public default KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + default KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { KEY_TYPE entry = iter.NEXT(); -#if TYPE_OBJECT - if(filter.getBoolean(entry)) return entry; -#else - if(filter.GET_VALUE(entry)) return entry; -#endif + if(filter.TEST_VALUE(entry)) return entry; } return EMPTY_VALUE; } 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 07fb25a5..f1b8dbaa 100644 --- a/src/builder/resources/speiger/assets/collections/templates/collections/Iterator.template +++ b/src/builder/resources/speiger/assets/collections/templates/collections/Iterator.template @@ -1,13 +1,14 @@ package speiger.src.collections.PACKAGE.collections; import java.util.Iterator; -#if !TYPE_OBJECT import java.util.Objects; +#if !TYPE_OBJECT import java.util.function.Consumer; import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; /** * A Type-Specific {@link Iterator} that reduces (un)boxing @@ -66,6 +67,18 @@ public interface ITERATOR KEY_GENERIC_TYPE extends Iterator } #endif + /** + * Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner. + * @param input the object that should be included + * @param action The action to be performed for each element + * @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) { + Objects.requireNonNull(action); + while(hasNext()) { action.accept(NEXT(), input); } + } + /** * Skips the Given amount of elements if possible. A Optimization function to skip elements faster if the implementation allows it. * @param amount the amount of elements that should be skipped 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 2f3247f0..bf84eba5 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template @@ -26,6 +26,8 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.utils.ARRAYS; import speiger.src.collections.PACKAGE.utils.ITERATORS; #if TYPE_OBJECT @@ -117,7 +119,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE * Creates a new ArrayList with a Copy of the array * @param a the array that should be copied */ - public ARRAY_LIST(KEY_TYPE... a) { + public ARRAY_LIST(KEY_TYPE... a) { this(a, 0, a.length); } @@ -588,6 +590,49 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE action.accept(data[i]); } + @Override + public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + for(int i = 0;i void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_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) { + Objects.requireNonNull(action); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) + action.accept(entry.value, input); + } + + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) { + if(filter.TEST_VALUE(entry.value)) return true; + } + return false; + } + + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) { + if(filter.TEST_VALUE(entry.value)) return false; + } + return true; + } + + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) { + if(!filter.TEST_VALUE(entry.value)) return false; + } + return true; + } + + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) { + if(filter.TEST_VALUE(entry.value)) return entry.value; + } + return EMPTY_VALUE; + } + @Override public KEY_TYPE set(int index, KEY_TYPE e) { checkRange(index); 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 b58e0e0f..9e290d88 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 @@ -4,12 +4,19 @@ import java.util.Comparator; import java.util.Map; import java.util.NoSuchElementException; import java.util.function.Consumer; +import java.util.Objects; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; #if !TYPE_OBJECT import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif +#if !TYPE_OBJECT && !VALUE_OBJECT +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +#endif +#if !TYPE_OBJECT || VALUE_BOOLEAN +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; +#endif import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; import speiger.src.collections.PACKAGE.maps.interfaces.MAP; @@ -25,6 +32,18 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR; import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER; import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR; #endif +#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT +import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; +#endif +#if !TYPE_OBJECT || !VALUE_BOOLEAN +#if !VALUE_OBJECT || SAME_TYPE +import speiger.src.collections.objects.functions.function.Object2BooleanFunction; +#endif +#endif +#if !SAME_TYPE +import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER; +import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; +#endif #if !TYPE_OBJECT import speiger.src.collections.objects.collections.ObjectBidirectionalIterator; import speiger.src.collections.objects.lists.ObjectListIterator; @@ -636,7 +655,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M @Override public void forEach(Consumer action) { int index = firstIndex; - while(index != -1){ + while(index != -1) { action.accept(new BasicEntryKV_BRACES(keys[index], values[index])); index = (int)links[index]; } @@ -646,13 +665,80 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M public void fastForEach(Consumer action) { BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); int index = firstIndex; - while(index != -1){ + while(index != -1) { entry.set(keys[index], values[index]); action.accept(entry); index = (int)links[index]; } } + @Override + public void forEach(E input, ObjectObjectConsumer action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + int index = firstIndex; + while(index != -1) { + action.accept(new BasicEntryKV_BRACES(keys[index], values[index]), input); + index = (int)links[index]; + } + } + + @Override + public boolean matchesAny(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + int index = firstIndex; + while(index != -1) { + entry.set(keys[index], values[index]); + if(filter.getBoolean(entry)) return true; + index = (int)links[index]; + } + return false; + } + + @Override + public boolean matchesNone(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + int index = firstIndex; + while(index != -1) { + entry.set(keys[index], values[index]); + if(filter.getBoolean(entry)) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public boolean matchesAll(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + int index = firstIndex; + while(index != -1) { + entry.set(keys[index], values[index]); + if(!filter.getBoolean(entry)) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return null; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + int index = firstIndex; + while(index != -1) { + entry.set(keys[index], values[index]); + if(filter.getBoolean(entry)) return entry; + index = (int)links[index]; + } + return null; + } + @Override @Deprecated public boolean contains(Object o) { @@ -789,17 +875,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M return POLL_LAST_ENTRY_KEY(); } -#if TYPE_OBJECT - @Override - public void forEach(Consumer KEY_SUPER_GENERIC_TYPE action) { - int index = firstIndex; - while(index != -1){ - action.accept(keys[index]); - index = (int)links[index]; - } - } - -#else @Override public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { int index = firstIndex; @@ -809,7 +884,65 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M } } -#endif + @Override + public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + int index = firstIndex; + while(index != -1){ + action.accept(keys[index], input); + index = (int)links[index]; + } + } + + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + int index = firstIndex; + while(index != -1){ + if(filter.TEST_VALUE(keys[index])) return true; + index = (int)links[index]; + } + return false; + } + + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + int index = firstIndex; + while(index != -1){ + if(filter.TEST_VALUE(keys[index])) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + int index = firstIndex; + while(index != -1){ + if(!filter.TEST_VALUE(keys[index])) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return EMPTY_KEY_VALUE; + int index = firstIndex; + while(index != -1){ + if(filter.TEST_VALUE(keys[index])) return keys[index]; + index = (int)links[index]; + } + return EMPTY_KEY_VALUE; + } + @Override public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; } @@ -858,16 +991,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M LINKED_CUSTOM_HASH_MAP.this.clear(); } -#if VALUE_OBJECT - @Override - public void forEach(Consumer VALUE_SUPER_GENERIC_TYPE action) { - int index = firstIndex; - while(index != -1){ - action.accept(values[index]); - index = (int)links[index]; - } - } -#else @Override public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) { int index = firstIndex; @@ -876,7 +999,65 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M index = (int)links[index]; } } -#endif + + @Override + public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VALUE_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + int index = firstIndex; + while(index != -1){ + action.accept(values[index], input); + index = (int)links[index]; + } + } + + @Override + public boolean matchesAny(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + int index = firstIndex; + while(index != -1){ + if(filter.VALUE_TEST_VALUE(values[index])) return true; + index = (int)links[index]; + } + return false; + } + + @Override + public boolean matchesNone(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + int index = firstIndex; + while(index != -1){ + if(filter.VALUE_TEST_VALUE(values[index])) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public boolean matchesAll(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + int index = firstIndex; + while(index != -1){ + if(!filter.VALUE_TEST_VALUE(values[index])) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return EMPTY_VALUE; + int index = firstIndex; + while(index != -1){ + if(filter.VALUE_TEST_VALUE(values[index])) return values[index]; + index = (int)links[index]; + } + return EMPTY_VALUE; + } } private class FastEntryIterator extends MapIterator implements ObjectListIterator { 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 daa649ef..c5cccfef 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 @@ -13,6 +13,12 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.function.FUNCTION; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; +#if !TYPE_OBJECT && !VALUE_OBJECT +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +#endif +#if !TYPE_OBJECT && !VALUE_BOOLEAN +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; +#endif import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; import speiger.src.collections.PACKAGE.lists.LIST; import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP; @@ -32,6 +38,18 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR; import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER; #endif #endif +#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT +import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; +#endif +#if !TYPE_OBJECT || !VALUE_BOOLEAN +#if !VALUE_OBJECT || SAME_TYPE +import speiger.src.collections.objects.functions.function.Object2BooleanFunction; +#endif +#endif +#if !SAME_TYPE +import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER; +import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; +#endif import speiger.src.collections.objects.collections.ObjectIterator; import speiger.src.collections.objects.sets.AbstractObjectSet; import speiger.src.collections.objects.sets.ObjectSet; @@ -452,12 +470,12 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL int index = findIndex(key); if(index < 0) { VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue()); - if(strategy.equals(newValue, getDefaultReturnValue())) return newValue; + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]); - if(strategy.equals(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { removeIndex(index); return newValue; } @@ -470,7 +488,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL int index = findIndex(key); if(index < 0) { VALUE_TYPE newValue = mappingFunction.GET_VALUE(key); - if(strategy.equals(newValue, getDefaultReturnValue())) return newValue; + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } @@ -482,7 +500,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]); - if(strategy.equals(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { removeIndex(index); return newValue; } @@ -494,7 +512,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { int index = findIndex(key); VALUE_TYPE newValue = index < 0 ? value : mappingFunction.APPLY_VALUE(values[index], value); - if(strategy.equals(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(index >= 0) removeIndex(index); } @@ -510,7 +528,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL KEY_TYPE key = entry.ENTRY_KEY(); int index = findIndex(key); VALUE_TYPE newValue = index < 0 ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE()); - if(strategy.equals(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(index >= 0) removeIndex(index); } @@ -753,13 +771,95 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL action.accept(entry); } for(int i = nullIndex-1;i>=0;i--) { - if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) { entry.set(keys[i], values[i]); action.accept(entry); } } } + @Override + public void forEach(E input, ObjectObjectConsumer action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + if(containsNull) action.accept(new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]), input); + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(new BasicEntryKV_BRACES(keys[i], values[i]), input); + } + } + + @Override + public boolean matchesAny(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + if(containsNull) { + entry.set(keys[nullIndex], values[nullIndex]); + if(filter.getBoolean(entry)) return true; + } + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) { + entry.set(keys[i], values[i]); + if(filter.getBoolean(entry)) return true; + } + } + return false; + } + + @Override + public boolean matchesNone(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + if(containsNull) { + entry.set(keys[nullIndex], values[nullIndex]); + if(filter.getBoolean(entry)) return false; + } + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) { + entry.set(keys[i], values[i]); + if(filter.getBoolean(entry)) return false; + } + } + return true; + } + + @Override + public boolean matchesAll(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + if(containsNull) { + entry.set(keys[nullIndex], values[nullIndex]); + if(!filter.getBoolean(entry)) return false; + } + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) { + entry.set(keys[i], values[i]); + if(!filter.getBoolean(entry)) return false; + } + } + return true; + } + + @Override + public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return null; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + if(containsNull) { + entry.set(keys[nullIndex], values[nullIndex]); + if(filter.getBoolean(entry)) return entry; + } + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) { + entry.set(keys[i], values[i]); + if(filter.getBoolean(entry)) return entry; + } + } + return null; + } + @Override public int size() { return CUSTOM_HASH_MAP.this.size(); @@ -841,22 +941,66 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL CUSTOM_HASH_MAP.this.clear(); } -#if TYPE_OBJECT - @Override - public void forEach(Consumer KEY_SUPER_GENERIC_TYPE action) { - if(containsNull) action.accept(keys[nullIndex]); - for(int i = nullIndex-1;i>=0;i--) - if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i]); - } - -#else @Override public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { if(containsNull) action.accept(keys[nullIndex]); for(int i = nullIndex-1;i>=0;i--) if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i]); } -#endif + + @Override + public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + if(containsNull) action.accept(keys[nullIndex], input); + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i], input); + } + } + + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return true; + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return true; + } + return false; + } + + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return false; + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return false; + } + return true; + } + + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + if(containsNull && !filter.TEST_VALUE(keys[nullIndex])) return false; + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && !filter.TEST_VALUE(keys[i])) return false; + } + return true; + } + + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return EMPTY_KEY_VALUE; + if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return keys[nullIndex]; + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return keys[i]; + } + return EMPTY_KEY_VALUE; + } } private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE { @@ -893,21 +1037,66 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL CUSTOM_HASH_MAP.this.clear(); } -#if VALUE_OBJECT - @Override - public void forEach(Consumer VALUE_SUPER_GENERIC_TYPE action) { - if(containsNull) action.accept(values[nullIndex]); - for(int i = nullIndex-1;i>=0;i--) - if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(values[i]); - } -#else @Override public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) { if(containsNull) action.accept(values[nullIndex]); for(int i = nullIndex-1;i>=0;i--) if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(values[i]); } -#endif + + @Override + public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VALUE_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + if(containsNull) action.accept(values[nullIndex], input); + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(values[i], input); + } + } + + @Override + public boolean matchesAny(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) return true; + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.VALUE_TEST_VALUE(values[i])) return true; + } + return false; + } + + @Override + public boolean matchesNone(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) return false; + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.VALUE_TEST_VALUE(values[i])) return false; + } + return true; + } + + @Override + public boolean matchesAll(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + if(containsNull && !filter.VALUE_TEST_VALUE(values[nullIndex])) return false; + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && !filter.VALUE_TEST_VALUE(values[i])) return false; + } + return true; + } + + @Override + public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return EMPTY_VALUE; + if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) return values[nullIndex]; + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.VALUE_TEST_VALUE(values[i])) return values[i]; + } + return EMPTY_VALUE; + } } private class FastEntryIterator extends MapIterator implements ObjectIterator { 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 54f7deea..14d764c7 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 @@ -4,15 +4,19 @@ import java.util.Comparator; import java.util.Map; import java.util.NoSuchElementException; import java.util.function.Consumer; -#if TYPE_OBJECT import java.util.Objects; -#endif import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; #if !TYPE_OBJECT import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif +#if !TYPE_OBJECT && !VALUE_OBJECT +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +#endif +#if !TYPE_OBJECT || VALUE_BOOLEAN +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; +#endif import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; import speiger.src.collections.PACKAGE.maps.interfaces.MAP; @@ -27,6 +31,18 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR; import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER; import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR; #endif +#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT +import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; +#endif +#if !TYPE_OBJECT || !VALUE_BOOLEAN +#if !VALUE_OBJECT || SAME_TYPE +import speiger.src.collections.objects.functions.function.Object2BooleanFunction; +#endif +#endif +#if !SAME_TYPE +import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER; +import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; +#endif #if !TYPE_OBJECT import speiger.src.collections.objects.collections.ObjectBidirectionalIterator; import speiger.src.collections.objects.lists.ObjectListIterator; @@ -633,6 +649,73 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G } } + @Override + public void forEach(E input, ObjectObjectConsumer action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + int index = firstIndex; + while(index != -1) { + action.accept(new BasicEntryKV_BRACES(keys[index], values[index]), input); + index = (int)links[index]; + } + } + + @Override + public boolean matchesAny(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + int index = firstIndex; + while(index != -1) { + entry.set(keys[index], values[index]); + if(filter.getBoolean(entry)) return true; + index = (int)links[index]; + } + return false; + } + + @Override + public boolean matchesNone(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + int index = firstIndex; + while(index != -1) { + entry.set(keys[index], values[index]); + if(filter.getBoolean(entry)) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public boolean matchesAll(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + int index = firstIndex; + while(index != -1) { + entry.set(keys[index], values[index]); + if(!filter.getBoolean(entry)) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return null; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + int index = firstIndex; + while(index != -1) { + entry.set(keys[index], values[index]); + if(filter.getBoolean(entry)) return entry; + index = (int)links[index]; + } + return null; + } + @Override @Deprecated public boolean contains(Object o) { @@ -769,17 +852,6 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G return POLL_LAST_ENTRY_KEY(); } -#if TYPE_OBJECT - @Override - public void forEach(Consumer KEY_SUPER_GENERIC_TYPE action) { - int index = firstIndex; - while(index != -1){ - action.accept(keys[index]); - index = (int)links[index]; - } - } - -#else @Override public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { int index = firstIndex; @@ -789,7 +861,65 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G } } -#endif + @Override + public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + int index = firstIndex; + while(index != -1){ + action.accept(keys[index], input); + index = (int)links[index]; + } + } + + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + int index = firstIndex; + while(index != -1){ + if(filter.TEST_VALUE(keys[index])) return true; + index = (int)links[index]; + } + return false; + } + + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + int index = firstIndex; + while(index != -1){ + if(filter.TEST_VALUE(keys[index])) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + int index = firstIndex; + while(index != -1){ + if(!filter.TEST_VALUE(keys[index])) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return EMPTY_KEY_VALUE; + int index = firstIndex; + while(index != -1){ + if(filter.TEST_VALUE(keys[index])) return keys[index]; + index = (int)links[index]; + } + return EMPTY_KEY_VALUE; + } + @Override public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; } @@ -838,25 +968,74 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G LINKED_HASH_MAP.this.clear(); } -#if VALUE_OBJECT - @Override - public void forEach(Consumer VALUE_SUPER_GENERIC_TYPE action) { - int index = firstIndex; - while(index != -1){ - action.accept(values[index]); - index = (int)links[index]; - } - } -#else @Override public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) { + Objects.requireNonNull(action); int index = firstIndex; while(index != -1){ action.accept(values[index]); index = (int)links[index]; } } -#endif + + @Override + public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VALUE_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + int index = firstIndex; + while(index != -1){ + action.accept(values[index], input); + index = (int)links[index]; + } + } + + @Override + public boolean matchesAny(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + int index = firstIndex; + while(index != -1){ + if(filter.VALUE_TEST_VALUE(values[index])) return true; + index = (int)links[index]; + } + return false; + } + + @Override + public boolean matchesNone(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + int index = firstIndex; + while(index != -1){ + if(filter.VALUE_TEST_VALUE(values[index])) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public boolean matchesAll(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + int index = firstIndex; + while(index != -1){ + if(!filter.VALUE_TEST_VALUE(values[index])) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return EMPTY_VALUE; + int index = firstIndex; + while(index != -1){ + if(filter.VALUE_TEST_VALUE(values[index])) return values[index]; + index = (int)links[index]; + } + return EMPTY_VALUE; + } } private class FastEntryIterator extends MapIterator implements ObjectListIterator { 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 b8a7d7c3..d36e4ef9 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 @@ -13,6 +13,12 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.function.FUNCTION; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; +#if !TYPE_OBJECT && !VALUE_OBJECT +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +#endif +#if !TYPE_OBJECT && !VALUE_BOOLEAN +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; +#endif import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; import speiger.src.collections.PACKAGE.lists.LIST; import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP; @@ -31,6 +37,18 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR; import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER; #endif #endif +#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT +import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; +#endif +#if !TYPE_OBJECT || !VALUE_BOOLEAN +#if !VALUE_OBJECT || SAME_TYPE +import speiger.src.collections.objects.functions.function.Object2BooleanFunction; +#endif +#endif +#if !SAME_TYPE +import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER; +import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; +#endif import speiger.src.collections.objects.collections.ObjectIterator; import speiger.src.collections.objects.sets.AbstractObjectSet; import speiger.src.collections.objects.sets.ObjectSet; @@ -413,12 +431,12 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE int index = findIndex(key); if(index < 0) { VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue()); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue; + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { removeIndex(index); return newValue; } @@ -431,7 +449,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE int index = findIndex(key); if(index < 0) { VALUE_TYPE newValue = mappingFunction.GET_VALUE(key); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue; + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } @@ -443,7 +461,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { removeIndex(index); return newValue; } @@ -455,7 +473,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { int index = findIndex(key); VALUE_TYPE newValue = index < 0 ? value : mappingFunction.APPLY_VALUE(values[index], value); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(index >= 0) removeIndex(index); } @@ -471,7 +489,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE KEY_TYPE key = entry.ENTRY_KEY(); int index = findIndex(key); VALUE_TYPE newValue = index < 0 ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE()); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(index >= 0) removeIndex(index); } @@ -720,6 +738,88 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE } } + @Override + public void forEach(E input, ObjectObjectConsumer action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + if(containsNull) action.accept(new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]), input); + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(new BasicEntryKV_BRACES(keys[i], values[i]), input); + } + } + + @Override + public boolean matchesAny(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + if(containsNull) { + entry.set(keys[nullIndex], values[nullIndex]); + if(filter.getBoolean(entry)) return true; + } + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i])) { + entry.set(keys[i], values[i]); + if(filter.getBoolean(entry)) return true; + } + } + return false; + } + + @Override + public boolean matchesNone(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + if(containsNull) { + entry.set(keys[nullIndex], values[nullIndex]); + if(filter.getBoolean(entry)) return false; + } + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i])) { + entry.set(keys[i], values[i]); + if(filter.getBoolean(entry)) return false; + } + } + return true; + } + + @Override + public boolean matchesAll(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + if(containsNull) { + entry.set(keys[nullIndex], values[nullIndex]); + if(!filter.getBoolean(entry)) return false; + } + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i])) { + entry.set(keys[i], values[i]); + if(!filter.getBoolean(entry)) return false; + } + } + return true; + } + + @Override + public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return null; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + if(containsNull) { + entry.set(keys[nullIndex], values[nullIndex]); + if(filter.getBoolean(entry)) return entry; + } + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i])) { + entry.set(keys[i], values[i]); + if(filter.getBoolean(entry)) return entry; + } + } + return null; + } + @Override public int size() { return HASH_MAP.this.size(); @@ -801,22 +901,66 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE HASH_MAP.this.clear(); } -#if TYPE_OBJECT - @Override - public void forEach(Consumer KEY_SUPER_GENERIC_TYPE action) { - if(containsNull) action.accept(keys[nullIndex]); - for(int i = nullIndex-1;i>=0;i--) - if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i]); - } - -#else @Override public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { if(containsNull) action.accept(keys[nullIndex]); for(int i = nullIndex-1;i>=0;i--) if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i]); } -#endif + + @Override + public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + if(containsNull) action.accept(keys[nullIndex], input); + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i], input); + } + } + + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return true; + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return true; + } + return false; + } + + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return false; + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return false; + } + return true; + } + + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + if(containsNull && !filter.TEST_VALUE(keys[nullIndex])) return false; + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i]) && !filter.TEST_VALUE(keys[i])) return false; + } + return true; + } + + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return EMPTY_KEY_VALUE; + if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return keys[nullIndex]; + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return keys[i]; + } + return EMPTY_KEY_VALUE; + } } private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE { @@ -853,21 +997,66 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE HASH_MAP.this.clear(); } -#if VALUE_OBJECT - @Override - public void forEach(Consumer VALUE_SUPER_GENERIC_TYPE action) { - if(containsNull) action.accept(values[nullIndex]); - for(int i = nullIndex-1;i>=0;i--) - if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(values[i]); - } -#else @Override public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) { if(containsNull) action.accept(values[nullIndex]); for(int i = nullIndex-1;i>=0;i--) if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(values[i]); } -#endif + + @Override + public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VALUE_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + if(containsNull) action.accept(values[nullIndex], input); + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(values[i], input); + } + } + + @Override + public boolean matchesAny(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) return true; + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.VALUE_TEST_VALUE(values[i])) return true; + } + return false; + } + + @Override + public boolean matchesNone(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) return false; + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.VALUE_TEST_VALUE(values[i])) return false; + } + return true; + } + + @Override + public boolean matchesAll(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + if(containsNull && !filter.VALUE_TEST_VALUE(values[nullIndex])) return false; + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i]) && !filter.VALUE_TEST_VALUE(values[i])) return false; + } + return true; + } + + @Override + public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return EMPTY_VALUE; + if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) return values[nullIndex]; + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.VALUE_TEST_VALUE(values[i])) return values[i]; + } + return EMPTY_VALUE; + } } private class FastEntryIterator extends MapIterator implements ObjectIterator { 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 47886fdc..a676aef8 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 @@ -11,6 +11,12 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.COMPARATOR; #endif +#if !TYPE_OBJECT && !VALUE_OBJECT +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +#endif +#if !TYPE_OBJECT && !VALUE_BOOLEAN +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; +#endif import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.function.FUNCTION; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; @@ -23,8 +29,18 @@ import speiger.src.collections.PACKAGE.utils.maps.MAPS; #if !TYPE_OBJECT import speiger.src.collections.PACKAGE.utils.ARRAYS; #endif - - +#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT +import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; +#endif +#if !TYPE_OBJECT || !VALUE_BOOLEAN +#if !VALUE_OBJECT || SAME_TYPE +import speiger.src.collections.objects.functions.function.Object2BooleanFunction; +#endif +#endif +#if !SAME_TYPE +import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER; +import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; +#endif #if !TYPE_OBJECT import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET; import speiger.src.collections.PACKAGE.sets.SET; @@ -588,6 +604,69 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_ } } + @Override + public void forEach(E input, ObjectObjectConsumer action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + int index = firstIndex; + while(index != -1) { + action.accept(new BasicEntryKV_BRACES(keys[index], values[index]), input); + index = (int)links[index]; + } + } + + @Override + public boolean matchesAny(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + int index = firstIndex; + while(index != -1) { + entry.set(keys[index], values[index]); + if(filter.getBoolean(entry)) return true; + } + return false; + } + + @Override + public boolean matchesNone(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + int index = firstIndex; + while(index != -1) { + entry.set(keys[index], values[index]); + if(filter.getBoolean(entry)) return false; + } + return true; + } + + @Override + public boolean matchesAll(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + int index = firstIndex; + while(index != -1) { + entry.set(keys[index], values[index]); + if(!filter.getBoolean(entry)) return false; + } + return true; + } + + @Override + public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return null; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + int index = firstIndex; + while(index != -1) { + entry.set(keys[index], values[index]); + if(filter.getBoolean(entry)) return entry; + } + return null; + } + @Override @Deprecated public boolean contains(Object o) { @@ -694,17 +773,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_ @Override public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); } -#if TYPE_OBJECT - @Override - public void forEach(Consumer KEY_SUPER_GENERIC_TYPE action) { - int index = firstIndex; - while(index != -1){ - action.accept(keys[index]); - index = (int)links[index]; - } - } - -#else @Override public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { int index = firstIndex; @@ -714,7 +782,65 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_ } } -#endif + @Override + public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + int index = firstIndex; + while(index != -1){ + action.accept(keys[index], input); + index = (int)links[index]; + } + } + + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + int index = firstIndex; + while(index != -1){ + if(filter.TEST_VALUE(keys[index])) return true; + index = (int)links[index]; + } + return false; + } + + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + int index = firstIndex; + while(index != -1){ + if(filter.TEST_VALUE(keys[index])) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + int index = firstIndex; + while(index != -1){ + if(!filter.TEST_VALUE(keys[index])) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return EMPTY_KEY_VALUE; + int index = firstIndex; + while(index != -1){ + if(filter.TEST_VALUE(keys[index])) return keys[index]; + index = (int)links[index]; + } + return EMPTY_KEY_VALUE; + } + @Override public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; } @@ -761,16 +887,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_ @Override public void clear() { throw new UnsupportedOperationException(); } -#if VALUE_OBJECT - @Override - public void forEach(Consumer VALUE_SUPER_GENERIC_TYPE action) { - int index = firstIndex; - while(index != -1){ - action.accept(values[index]); - index = (int)links[index]; - } - } -#else @Override public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) { int index = firstIndex; @@ -779,7 +895,65 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_ index = (int)links[index]; } } -#endif + + @Override + public void forEach(E input, VALUE_BI_OBJECT_CONSUMER VALUE_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + int index = firstIndex; + while(index != -1){ + action.accept(values[index], input); + index = (int)links[index]; + } + } + + @Override + public boolean matchesAny(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + int index = firstIndex; + while(index != -1){ + if(filter.VALUE_TEST_VALUE(values[index])) return true; + index = (int)links[index]; + } + return false; + } + + @Override + public boolean matchesNone(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + int index = firstIndex; + while(index != -1){ + if(filter.VALUE_TEST_VALUE(values[index])) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public boolean matchesAll(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + int index = firstIndex; + while(index != -1){ + if(!filter.VALUE_TEST_VALUE(values[index])) return false; + index = (int)links[index]; + } + return true; + } + + @Override + public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return EMPTY_VALUE; + int index = firstIndex; + while(index != -1){ + if(filter.VALUE_TEST_VALUE(values[index])) return values[index]; + index = (int)links[index]; + } + return EMPTY_VALUE; + } } private class FastEntryIterator extends MapIterator implements ObjectListIterator { 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 bd7f107d..cbb630ad 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 @@ -12,6 +12,12 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif +#if !TYPE_OBJECT && !VALUE_OBJECT +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +#endif +#if !TYPE_OBJECT && !VALUE_BOOLEAN +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; +#endif import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.function.FUNCTION; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; @@ -33,6 +39,18 @@ import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER; import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR; #endif #endif +#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT +import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; +#endif +#if !TYPE_OBJECT || !VALUE_BOOLEAN +#if !VALUE_OBJECT || SAME_TYPE +import speiger.src.collections.objects.functions.function.Object2BooleanFunction; +#endif +#endif +#if !SAME_TYPE +import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER; +import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; +#endif #if !VALUE_OBJECT import speiger.src.collections.objects.collections.ObjectIterator; #endif @@ -443,12 +461,12 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN int index = findIndex(key); if(index == -1) { VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue()); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue; + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { removeIndex(index); return newValue; } @@ -461,7 +479,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN int index = findIndex(key); if(index == -1) { VALUE_TYPE newValue = mappingFunction.GET_VALUE(key); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue; + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } @@ -473,7 +491,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN int index = findIndex(key); if(index == -1) return getDefaultReturnValue(); VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { removeIndex(index); return newValue; } @@ -485,7 +503,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { int index = findIndex(key); VALUE_TYPE newValue = index == -1 ? value : mappingFunction.APPLY_VALUE(values[index], value); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(index >= 0) removeIndex(index); } @@ -501,7 +519,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN KEY_TYPE key = entry.ENTRY_KEY(); int index = findIndex(key); VALUE_TYPE newValue = index == -1 ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE()); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(index >= 0) removeIndex(index); } @@ -1103,12 +1121,15 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN @Override public void forEach(Consumer action) { + Objects.requireNonNull(action); for(int i = 0;i action) { + Objects.requireNonNull(action); + if(size() <= 0) return; BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); for(int i = 0;i void forEach(E input, ObjectObjectConsumer action) { + Objects.requireNonNull(action); + for(int i = 0;i filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + for(int i = 0;i filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + for(int i = 0;i filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + for(int i = 0;i filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return null; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + for(int i = 0;i action) { + public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { + Objects.requireNonNull(action); for(int i = 0;i void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + for(int i = 0;i action) { + public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) { + Objects.requireNonNull(action); for(int i = 0;i void forEach(E input, VALUE_BI_OBJECT_CONSUMER VALUE_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + for(int i = 0;i { @@ -1498,12 +1652,15 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN @Override public void forEach(Consumer action) { + Objects.requireNonNull(action); for(int i = 0;i action) { + Objects.requireNonNull(action); + if(size() <= 0) return; BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); for(int i = 0;i void forEach(E input, ObjectObjectConsumer action) { + Objects.requireNonNull(action); + for(int i = 0;i filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + for(int i = 0;i filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + for(int i = 0;i filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + for(int i = 0;i filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return null; + BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + for(int i = 0;i action) { + public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { + Objects.requireNonNull(action); for(int i = 0;i void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + for(int i = 0;i action) { + public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) { + Objects.requireNonNull(action); for(int i = 0;i { diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template index 85568899..4b98dc8e 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template @@ -479,12 +479,12 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_ Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key); if(entry == null) { VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue()); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue; + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { removeNode(entry); return newValue; } @@ -497,7 +497,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_ Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key); if(entry == null) { VALUE_TYPE newValue = mappingFunction.GET_VALUE(key); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue; + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } @@ -509,7 +509,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_ Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key); if(entry == null) return getDefaultReturnValue(); VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { removeNode(entry); return newValue; } @@ -521,7 +521,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_ public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key); VALUE_TYPE newValue = entry == null ? value : mappingFunction.APPLY_VALUE(entry.value, value); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(entry != null) removeNode(entry); } @@ -537,7 +537,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_ KEY_TYPE key = entry.ENTRY_KEY(); Entry KEY_VALUE_GENERIC_TYPE subEntry = findNode(key); VALUE_TYPE newValue = subEntry == null ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(subEntry.value, entry.ENTRY_VALUE()); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(subEntry != null) removeNode(subEntry); } diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template index e5b982f8..c2740e8d 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template @@ -478,12 +478,12 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key); if(entry == null) { VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue()); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue; + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { removeNode(entry); return newValue; } @@ -496,7 +496,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key); if(entry == null) { VALUE_TYPE newValue = mappingFunction.GET_VALUE(key); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue; + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } @@ -508,7 +508,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key); if(entry == null) return getDefaultReturnValue(); VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { removeNode(entry); return newValue; } @@ -520,7 +520,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key); VALUE_TYPE newValue = entry == null ? value : mappingFunction.APPLY_VALUE(entry.value, value); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(entry != null) removeNode(entry); } @@ -536,7 +536,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G KEY_TYPE key = entry.ENTRY_KEY(); Entry KEY_VALUE_GENERIC_TYPE subEntry = findNode(key); VALUE_TYPE newValue = subEntry == null ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(subEntry.value, entry.ENTRY_VALUE()); - if(KEY_EQUALS(newValue, getDefaultReturnValue())) { + if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(subEntry != null) removeNode(subEntry); } diff --git a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template index 6fd332a9..ac7a955d 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template @@ -3,13 +3,18 @@ package speiger.src.collections.PACKAGE.queues; #if TYPE_OBJECT import java.util.Arrays; import java.util.Comparator; +import java.util.function.Consumer; #endif +import java.util.Objects; import java.util.NoSuchElementException; import speiger.src.collections.PACKAGE.collections.ITERATOR; #if !TYPE_OBJECT import speiger.src.collections.PACKAGE.functions.COMPARATOR; +import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.utils.ITrimmable; /** @@ -157,7 +162,6 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G @Override public boolean removeLast(KEY_TYPE e) { - if(first == last) return false; if(first == last) return false; for(int i = size()-1;i>=0;i--) { int index = (first + i) % array.length; @@ -221,6 +225,65 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G @Override public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() { return null; } + @Override + public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { + Objects.requireNonNull(action); + if(first == last) return; + for(int i = 0,m=size();i void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + if(first == last) return; + for(int i = 0,m=size();i void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + for(int i = 0,m=size;i void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + for(int i = 0,m=size;i -#else public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TYPE -#endif { /** * @return true if the PriorityQueue is empty 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 65b768c2..cea16dee 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template @@ -3,13 +3,18 @@ package speiger.src.collections.PACKAGE.sets; import java.util.Collection; #if TYPE_OBJECT import java.util.Comparator; +import java.util.function.Consumer; #endif import java.util.Iterator; import java.util.NoSuchElementException; +import java.util.Objects; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; #if !TYPE_OBJECT import speiger.src.collections.PACKAGE.functions.COMPARATOR; +import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; @@ -290,6 +295,57 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE #endif } + @Override + public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { + Objects.requireNonNull(action); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) { + action.accept(entry.key); + } + } + + @Override + public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) + action.accept(entry.key, input); + } + + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) { + if(filter.TEST_VALUE(entry.key)) return true; + } + return false; + } + + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) { + if(filter.TEST_VALUE(entry.key)) return false; + } + return true; + } + + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) { + if(!filter.TEST_VALUE(entry.key)) return false; + } + return true; + } + + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) { + if(filter.TEST_VALUE(entry.key)) return entry.key; + } + return EMPTY_VALUE; + } + protected Entry KEY_GENERIC_TYPE findNode(KEY_TYPE o) { Entry KEY_GENERIC_TYPE node = tree; int compare; 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 9dc302f2..13780e3c 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/ArraySet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/ArraySet.template @@ -12,10 +12,12 @@ import java.util.Set; #if PRIMITIVES import java.util.function.JAVA_PREDICATE; #endif - import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.ITERATOR; + +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; #if !TYPE_OBJECT import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.CONSUMER; @@ -341,21 +343,55 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im } #endif -#if TYPE_OBJECT @Override - public void forEach(Consumer KEY_SUPER_GENERIC_TYPE action) { + public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { Objects.requireNonNull(action); for(int i = 0;i void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { Objects.requireNonNull(action); - for(int i = 0;i=0;i--) diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/ImmutableOpenHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/ImmutableOpenHashSet.template index 0387ed9b..f55c6ae3 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/ImmutableOpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/ImmutableOpenHashSet.template @@ -16,6 +16,8 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; import speiger.src.collections.PACKAGE.utils.ARRAYS; import speiger.src.collections.PACKAGE.utils.ITERATORS; @@ -286,13 +288,64 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI #endif @Override public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { + Objects.requireNonNull(action); int index = firstIndex; - while(index != -1){ + while(index != -1) { action.accept(keys[index]); index = (int)links[index]; } } + @Override + public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + int index = firstIndex; + while(index != -1) { + action.accept(keys[index], input); + index = (int)links[index]; + } + } + + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + int index = firstIndex; + while(index != -1) { + if(filter.TEST_VALUE(keys[index])) return true; + } + return false; + } + + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + int index = firstIndex; + while(index != -1) { + if(filter.TEST_VALUE(keys[index])) return false; + } + return true; + } + + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + int index = firstIndex; + while(index != -1) { + if(!filter.TEST_VALUE(keys[index])) return false; + } + return true; + } + + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + int index = firstIndex; + while(index != -1) { + if(filter.TEST_VALUE(keys[index])) return keys[index]; + } + return EMPTY_VALUE; + } + @Override public LIST_ITERATOR KEY_GENERIC_TYPE iterator() { return new SetIterator(); 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 2d3f78c0..fa0f1b98 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template @@ -4,6 +4,7 @@ package speiger.src.collections.PACKAGE.sets; import java.util.Comparator; import java.util.function.Consumer; #endif +import java.util.Objects; import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; @@ -21,6 +22,8 @@ import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; import speiger.src.collections.PACKAGE.utils.ITERATORS; import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.utils.STRATEGY; import speiger.src.collections.utils.HashUtil; import speiger.src.collections.utils.SanityChecks; @@ -522,6 +525,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY @Override public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { + Objects.requireNonNull(action); int index = firstIndex; while(index != -1){ action.accept(keys[index]); @@ -529,6 +533,56 @@ 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) { + Objects.requireNonNull(action); + int index = firstIndex; + while(index != -1) { + action.accept(keys[index], input); + index = (int)links[index]; + } + } + + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + int index = firstIndex; + while(index != -1) { + if(filter.TEST_VALUE(keys[index])) return true; + } + return false; + } + + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + int index = firstIndex; + while(index != -1) { + if(filter.TEST_VALUE(keys[index])) return false; + } + return true; + } + + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + int index = firstIndex; + while(index != -1) { + if(!filter.TEST_VALUE(keys[index])) return false; + } + return true; + } + + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + int index = firstIndex; + while(index != -1) { + if(filter.TEST_VALUE(keys[index])) return keys[index]; + } + return EMPTY_VALUE; + } + @Override public LIST_ITERATOR KEY_GENERIC_TYPE iterator() { return new SetIterator(); 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 189fdb9a..ed91cd51 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template @@ -6,8 +6,8 @@ import java.util.Comparator; import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; -#if TYPE_OBJECT import java.util.Objects; +#if TYPE_OBJECT import java.util.function.Consumer; #endif @@ -20,6 +20,8 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; #if !TYPE_OBJECT import speiger.src.collections.PACKAGE.utils.ITERATORS; @@ -378,6 +380,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE @Override public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { + Objects.requireNonNull(action); int index = firstIndex; while(index != -1){ action.accept(keys[index]); @@ -385,6 +388,56 @@ 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) { + Objects.requireNonNull(action); + int index = firstIndex; + while(index != -1) { + action.accept(keys[index], input); + index = (int)links[index]; + } + } + + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + int index = firstIndex; + while(index != -1) { + if(filter.TEST_VALUE(keys[index])) return true; + } + return false; + } + + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + int index = firstIndex; + while(index != -1) { + if(filter.TEST_VALUE(keys[index])) return false; + } + return true; + } + + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + int index = firstIndex; + while(index != -1) { + if(!filter.TEST_VALUE(keys[index])) return false; + } + return true; + } + + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + int index = firstIndex; + while(index != -1) { + if(filter.TEST_VALUE(keys[index])) return keys[index]; + } + return EMPTY_VALUE; + } + @Override protected void onNodeAdded(int pos) { if(size == 0) { 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 74f15ca7..b031c5bc 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; +import java.util.Objects; #if TYPE_OBJECT import java.util.function.Consumer; #endif @@ -16,6 +17,8 @@ import speiger.src.collections.PACKAGE.lists.LIST; import speiger.src.collections.PACKAGE.utils.ITERATORS; import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.utils.STRATEGY; import speiger.src.collections.utils.HashUtil; @@ -460,10 +463,64 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T if(size() <= 0) return; if(containsNull) action.accept(keys[nullIndex]); for(int i = nullIndex-1;i>=0;i--) { - if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i]); + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i]); } } + @Override + public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + if(size() <= 0) return; + if(containsNull) action.accept(keys[nullIndex], input); + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i], input); + } + } + + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return true; + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return true; + } + return false; + } + + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return false; + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return false; + } + return true; + } + + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + if(containsNull && !filter.TEST_VALUE(keys[nullIndex])) return false; + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && !filter.TEST_VALUE(keys[i])) return false; + } + return true; + } + + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return EMPTY_VALUE; + if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return keys[nullIndex]; + for(int i = nullIndex-1;i>=0;i--) { + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return keys[i]; + } + return EMPTY_VALUE; + } + private class SetIterator implements ITERATOR KEY_GENERIC_TYPE { int pos = nullIndex; int lastReturned = -1; 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 61ec8a90..d5205586 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template @@ -17,6 +17,8 @@ import speiger.src.collections.PACKAGE.lists.LIST; import speiger.src.collections.PACKAGE.utils.ITERATORS; import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.utils.HashUtil; import speiger.src.collections.utils.ITrimmable; import speiger.src.collections.utils.SanityChecks; @@ -334,6 +336,60 @@ 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) { + Objects.requireNonNull(action); + if(size() <= 0) return; + if(containsNull) action.accept(keys[nullIndex], input); + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i], input); + } + } + + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return false; + if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return true; + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return true; + } + return false; + } + + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return false; + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return false; + } + return true; + } + + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return true; + if(containsNull && !filter.TEST_VALUE(keys[nullIndex])) return false; + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i]) && !filter.TEST_VALUE(keys[i])) return false; + } + return true; + } + + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + if(size() <= 0) return EMPTY_VALUE; + if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return keys[nullIndex]; + for(int i = nullIndex-1;i>=0;i--) { + if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return keys[i]; + } + return EMPTY_VALUE; + } + private void ensureCapacity(int newCapacity) { int size = HashUtil.arraySize(newCapacity, loadFactor); if(size > nullIndex) rehash(size); 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 d3d1454d..46bcaeeb 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/RBTreeSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/RBTreeSet.template @@ -3,13 +3,18 @@ package speiger.src.collections.PACKAGE.sets; import java.util.Collection; #if TYPE_OBJECT import java.util.Comparator; +import java.util.function.Consumer; #endif import java.util.Iterator; import java.util.NoSuchElementException; +import java.util.Objects; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; #if !TYPE_OBJECT import speiger.src.collections.PACKAGE.functions.COMPARATOR; +import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif +import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER; +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; @@ -290,6 +295,57 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE #endif } + @Override + public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { + Objects.requireNonNull(action); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) { + action.accept(entry.key); + } + } + + @Override + public void forEach(E input, BI_OBJECT_CONSUMER KEY_VALUE_SPECIAL_GENERIC_TYPE action) { + Objects.requireNonNull(action); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) + action.accept(entry.key, input); + } + + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) { + if(filter.TEST_VALUE(entry.key)) return true; + } + return false; + } + + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) { + if(filter.TEST_VALUE(entry.key)) return false; + } + return true; + } + + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) { + if(!filter.TEST_VALUE(entry.key)) return false; + } + return true; + } + + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + Objects.requireNonNull(filter); + for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) { + if(filter.TEST_VALUE(entry.key)) return entry.key; + } + return EMPTY_VALUE; + } + protected Entry KEY_GENERIC_TYPE findNode(KEY_TYPE o) { Entry KEY_GENERIC_TYPE node = tree; int compare;