Breaking update
- Added: Optionals for the missing JDK ones. - Removed: Default values for Reduce and FindFirst. Using Optionals instead.
This commit is contained in:
+11
-5
@@ -7,12 +7,18 @@ import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#endif
|
||||
import java.util.NoSuchElementException;
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
@@ -318,17 +324,17 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
int index = (first + i) % array.length;
|
||||
if(filter.test(array[index])) {
|
||||
KEY_TYPE data = array[index];
|
||||
removeIndex(index);
|
||||
return data;
|
||||
return OPTIONAL.GET_OPTIONAL(data);
|
||||
}
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@@ -355,7 +361,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
|
||||
#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;
|
||||
@@ -367,7 +373,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user