Implemented ForEachIndexed into all collections

This commit is contained in:
Speiger 2022-12-16 13:03:28 +01:00
parent 3f6e7fbb88
commit 477f3c9f40
22 changed files with 538 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import java.util.Comparator;
#endif
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@ -110,6 +111,17 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
}
#endif
/**
* A Indexed forEach implementation that allows you to keep track of how many elements were already iterated over.
* @param action The action to be performed for each element
* @throws java.lang.NullPointerException if the specified action is null
*/
public default void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();action.accept(index++, iter.NEXT()));
}
/**
* 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

View File

@ -366,6 +366,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
* @param action The action to be performed for each element
* @throws java.lang.NullPointerException if the specified action is null
*/
@Override
public default void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
for(int i = 0,m=size();i<m;action.accept(i, GET_KEY(i++)));

View File

@ -23,6 +23,13 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
#if !VALUE_BOOLEAN || !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
@ -673,6 +680,26 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
}
}
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
int count = 0;
for(int i = 0,m=segments.length;i<m;i++) {
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1) {
action.accept(count++, new BasicEntryKV_BRACES(seg.keys[index], seg.values[index]));
index = (int)seg.links[index];
}
}
finally {
seg.unlockRead(stamp);
}
}
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
@ -982,6 +1009,26 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
}
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int count = 0;
for(int i = 0,m=segments.length;i<m;i++) {
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1){
action.accept(count++, seg.keys[index]);
index = (int)seg.links[index];
}
}
finally {
seg.unlockRead(stamp);
}
}
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
@ -1230,6 +1277,26 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
}
}
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int count = 0;
for(int i = 0,m=segments.length;i<m;i++) {
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1){
action.accept(count++, seg.values[index]);
index = (int)seg.links[index];
}
}
finally {
seg.unlockRead(stamp);
}
}
}
@Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -19,6 +19,13 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
#if !TYPE_OBJECT && !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
@ -687,6 +694,18 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
}
}
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1) {
action.accept(count++, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
@ -948,6 +967,18 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
}
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1){
action.accept(count++, keys[index]);
index = (int)links[index];
}
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
@ -1111,6 +1142,18 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
}
}
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1){
action.accept(count++, values[index]);
index = (int)links[index];
}
}
@Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -20,6 +20,13 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
#if !VALUE_BOOLEAN || !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
@ -873,6 +880,16 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
}
}
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, new BasicEntryKV_BRACES(keys[i], values[i]));
}
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
@ -1110,6 +1127,16 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i]);
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, keys[nullIndex]);
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, keys[i]);
}
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
@ -1266,6 +1293,16 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(values[i]);
}
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, values[nullIndex]);
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, values[i]);
}
}
@Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -19,6 +19,13 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
#if !TYPE_OBJECT && !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
@ -691,6 +698,18 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
}
}
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1) {
action.accept(count++, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
@ -947,6 +966,18 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
}
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1){
action.accept(count++, keys[index]);
index = (int)links[index];
}
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
@ -1111,6 +1142,18 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
}
}
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1){
action.accept(count++, values[index]);
index = (int)links[index];
}
}
@Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -20,6 +20,13 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
#if !VALUE_BOOLEAN || !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
@ -832,6 +839,16 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
}
}
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, new BasicEntryKV_BRACES(keys[i], values[i]));
}
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
@ -1065,6 +1082,16 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i]);
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, keys[nullIndex]);
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, keys[i]);
}
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
@ -1221,6 +1248,16 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(values[i]);
}
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, values[nullIndex]);
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, values[i]);
}
}
@Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -19,6 +19,13 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
@ -664,6 +671,18 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
}
}
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1) {
action.accept(count++, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
@ -892,6 +911,18 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
}
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1){
action.accept(count++, keys[index]);
index = (int)links[index];
}
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
@ -1053,6 +1084,18 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
}
}
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1){
action.accept(count++, values[index]);
index = (int)links[index];
}
}
@Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -19,6 +19,13 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
@ -793,6 +800,14 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
}
}
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;i++) {
action.accept(i, new BasicEntryKV_BRACES(keys[i], values[i]));
}
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
@ -991,11 +1006,16 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
for(int i = 0;i<size;action.accept(keys[i++]));
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;action.accept(i, keys[i++]));
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;action.accept(input, keys[i++]));
}
@Override
@ -1125,6 +1145,12 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
for(int i = 0;i<size;action.accept(values[i++]));
}
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;action.accept(i, values[i++]));
}
@Override
public boolean matchesAny(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -24,6 +24,13 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
#if !VALUE_BOOLEAN || !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
#endif
@ -1153,6 +1160,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
action.accept(entry.key);
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
action.accept(index++, entry.key);
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
@ -1841,6 +1856,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
action.accept(index++, new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
@ -1973,6 +1996,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
action.accept(entry.value);
}
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
action.accept(index++, entry.value);
}
@Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
@ -2321,6 +2352,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
action.accept(entry.value);
}
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(index++, entry.value);
}
@Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
@ -2478,6 +2517,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(index++, new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);

View File

@ -23,6 +23,13 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
#if !VALUE_BOOLEAN || !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
#endif
@ -1209,6 +1216,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
action.accept(entry.key);
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
action.accept(index++, entry.key);
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
@ -1907,6 +1922,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
action.accept(index++, new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
@ -2039,6 +2062,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
action.accept(entry.value);
}
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
action.accept(index++, entry.value);
}
@Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
@ -2387,6 +2418,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
action.accept(entry.value);
}
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(index++, entry.value);
}
@Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
@ -2544,6 +2583,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(index++, new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);

View File

@ -17,6 +17,7 @@ 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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@ -262,6 +263,15 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
clearAndTrim(0);
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(first == last) return;
for(int i = 0,m=size();i<m;i++)
action.accept(i, array[(first + i) % array.length]);
clearAndTrim(0);
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -18,6 +18,7 @@ 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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@ -214,6 +215,13 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
return value;
}
@Override
public KEY_TYPE first() {
if(isEmpty()) throw new NoSuchElementException();
if(firstIndex == -1) findFirstIndex();
return array[firstIndex];
}
@Override
public KEY_TYPE peek(int index) {
if(index < 0 || index >= size) throw new NoSuchElementException();
@ -268,6 +276,12 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
for(int i = 0,m=size;i<m;i++) action.accept(dequeue());
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
for(int i = 0,m=size;i<m;i++) action.accept(i, dequeue());
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -18,6 +18,7 @@ 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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@ -255,6 +256,12 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
for(int i = 0,m=size;i<m;i++) action.accept(dequeue());
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
for(int i = 0,m=size;i<m;i++) action.accept(i, dequeue());
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -19,6 +19,7 @@ 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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@ -359,6 +360,15 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
}
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
action.accept(index++, entry.key);
}
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
@ -1198,6 +1208,15 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
}
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
action.accept(index++, entry.key);
}
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -19,6 +19,7 @@ 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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@ -396,6 +397,12 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
for(int i = 0;i<size;action.accept(data[i++]));
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;action.accept(i, data[i++]));
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -19,6 +19,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@ -328,6 +329,17 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
}
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int count = 0;
int index = firstIndex;
while(index != -1) {
action.accept(count++, keys[index]);
index = (int)links[index];
}
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -23,6 +23,7 @@ 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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@ -537,6 +538,17 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
}
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int count = 0;
int index = firstIndex;
while(index != -1) {
action.accept(count++, keys[index]);
index = (int)links[index];
}
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -21,6 +21,7 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@ -392,6 +393,17 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
}
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int count = 0;
int index = firstIndex;
while(index != -1) {
action.accept(count++, keys[index]);
index = (int)links[index];
}
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -20,6 +20,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.utils.ITERATORS;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@ -506,6 +507,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
@Override
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
@ -513,6 +515,16 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
}
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, keys[nullIndex]);
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, keys[i]);
}
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -20,6 +20,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.utils.ITERATORS;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@ -376,6 +377,16 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
}
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, keys[nullIndex]);
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, keys[i]);
}
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);

View File

@ -19,6 +19,7 @@ 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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@ -359,6 +360,14 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
}
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(index++, entry.key);
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
@ -1259,6 +1268,15 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
}
}
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
action.accept(index++, entry.key);
}
}
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);