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
@@ -5,6 +5,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 TYPE_OBJECT
import java.util.function.Consumer;
import java.util.function.BiFunction;
@@ -21,6 +24,9 @@ import speiger.src.collections.PACKAGE.collections.BI_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
@@ -511,7 +517,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
#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;
@@ -524,18 +530,18 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
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