Breaking update

- Added: Optionals for the missing JDK ones.
- Removed: Default values for Reduce and FindFirst. Using Optionals
instead.
This commit is contained in:
2026-05-11 18:00:00 +02:00
parent c6f656ee66
commit 3d39d5526d
34 changed files with 597 additions and 297 deletions
@@ -9,6 +9,9 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
#if JDK_TYPE
import java.util.OPTIONAL;
#endif
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
@@ -19,6 +22,9 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
#if !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
#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
@@ -414,7 +420,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_VALUE;
boolean empty = true;
@@ -427,18 +433,18 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
else state = operator.APPLY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int index = firstIndex;
while(index != -1) {
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OPTIONAL.GET_OPTIONAL(keys[index]);
index = (int)links[index];
}
return EMPTY_VALUE;
return OPTIONAL.empty();
}
@Override