Fixes and a lot new features. But still WIP
- Fixed: Supplier get function wasn't referencing original function. - Added: addIfPresent/Absent to lists - Added: distinct, limit and peek iterators - Added: Iterable's can now reduce its contents
This commit is contained in:
@@ -18,6 +18,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
@@ -422,6 +423,32 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(int i = 0;i<size;i++) {
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = data[i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
|
||||
Reference in New Issue
Block a user