Sync Latest Update
This commit is contained in:
parent
720fa44eed
commit
4c565f2cf3
@ -34,7 +34,8 @@ public class FunctionModule extends BaseModule
|
|||||||
protected void loadBlockades()
|
protected void loadBlockades()
|
||||||
{
|
{
|
||||||
if(keyType.isObject()) addBlockedFiles("Consumer", "Comparator");
|
if(keyType.isObject()) addBlockedFiles("Consumer", "Comparator");
|
||||||
if(!MODULE.isEnabled()) addBlockedFiles("Consumer", "BiConsumer", "Comparator", "Supplier", "Function", "UnaryOperator");
|
if(!MODULE.isEnabled()) addBlockedFiles("Consumer", "BiConsumer", "Comparator", "Supplier", "Optional", "Function", "UnaryOperator");
|
||||||
|
if(!keyType.needsCustomJDKType()) addBlockedFiles("Optional");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -60,6 +61,7 @@ public class FunctionModule extends BaseModule
|
|||||||
}
|
}
|
||||||
else addBiRequirement("Function");
|
else addBiRequirement("Function");
|
||||||
addRemapper("BiConsumer", "%sConsumer");
|
addRemapper("BiConsumer", "%sConsumer");
|
||||||
|
addRemapper("Optional", "Optional%s");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -94,6 +96,8 @@ public class FunctionModule extends BaseModule
|
|||||||
|
|
||||||
addFunctionMappers("PREDICATE", "%sPredicate");
|
addFunctionMappers("PREDICATE", "%sPredicate");
|
||||||
addClassMapper("SUPPLIER", "Supplier");
|
addClassMapper("SUPPLIER", "Supplier");
|
||||||
|
addSimpleMapper("OPTIONAL", keyType.isObject() ? "Optional" : String.format("Optional%s", keyType.getFileType()));
|
||||||
|
addSimpleMapper("VALUE_OPTIONAL", valueType.isObject() ? "Optional" : String.format("Optional%s", valueType.getFileType()));
|
||||||
addAbstractMapper("SINGLE_UNARY_OPERATOR", "%1$s%1$sUnaryOperator");
|
addAbstractMapper("SINGLE_UNARY_OPERATOR", "%1$s%1$sUnaryOperator");
|
||||||
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
|
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
|
||||||
if(keyType.isObject())
|
if(keyType.isObject())
|
||||||
|
|||||||
@ -60,6 +60,8 @@ public class JavaModule extends BaseModule
|
|||||||
addSimpleMapper("APPLY_KEY_VALUE", keyType.isObject() ? "apply" : "applyAs"+keyType.getNonFileType());
|
addSimpleMapper("APPLY_KEY_VALUE", keyType.isObject() ? "apply" : "applyAs"+keyType.getNonFileType());
|
||||||
addSimpleMapper("APPLY_VALUE", valueType.isObject() ? "apply" : "applyAs"+valueType.getNonFileType());
|
addSimpleMapper("APPLY_VALUE", valueType.isObject() ? "apply" : "applyAs"+valueType.getNonFileType());
|
||||||
addSimpleMapper("APPLY_CAST", "applyAs"+keyType.getCustomJDKType().getNonFileType());
|
addSimpleMapper("APPLY_CAST", "applyAs"+keyType.getCustomJDKType().getNonFileType());
|
||||||
|
addSimpleMapper("GET_OPTIONAL", keyType.isObject() ? "ofNullable" : "of");
|
||||||
|
addSimpleMapper("GET_OPTIONAL_VALUE", valueType.isObject() ? "ofNullable" : "of");
|
||||||
|
|
||||||
//Shared by Maps and Pairs so moved to java.
|
//Shared by Maps and Pairs so moved to java.
|
||||||
addFunctionMappers("ENTRY_KEY", "get%sKey");
|
addFunctionMappers("ENTRY_KEY", "get%sKey");
|
||||||
|
|||||||
@ -5,6 +5,9 @@ import java.util.function.Consumer;
|
|||||||
#if JDK_FUNCTION
|
#if JDK_FUNCTION
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
|
|
||||||
@ -30,6 +33,9 @@ import speiger.src.collections.PACKAGE.collections.OUTPUT_ITERABLE;
|
|||||||
#endif
|
#endif
|
||||||
#enditerate
|
#enditerate
|
||||||
#endif
|
#endif
|
||||||
|
#if !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
@ -408,13 +414,13 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
|||||||
* @param filter that should be applied
|
* @param filter that should be applied
|
||||||
* @return the found value or the null equivalent variant.
|
* @return the found value or the null equivalent variant.
|
||||||
*/
|
*/
|
||||||
default KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
default OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
KEY_TYPE entry = iter.NEXT();
|
KEY_TYPE entry = iter.NEXT();
|
||||||
if(filter.test(entry)) return entry;
|
if(filter.test(entry)) return OPTIONAL.GET_OPTIONAL(entry);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -459,7 +465,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
|||||||
* @param operator the operation that should be applied
|
* @param operator the operation that should be applied
|
||||||
* @return the reduction result, returns null value if nothing was found
|
* @return the reduction result, returns null value if nothing was found
|
||||||
*/
|
*/
|
||||||
default KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
default OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -471,7 +477,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, iter.NEXT());
|
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -0,0 +1,89 @@
|
|||||||
|
package speiger.src.collections.PACKAGE.functions;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public final class OPTIONAL KEY_GENERIC_TYPE {
|
||||||
|
private static final OPTIONAL NO_GENERIC_TYPE EMPTY = new OPTIONALBRACES();
|
||||||
|
|
||||||
|
private final boolean isPresent;
|
||||||
|
private final KEY_TYPE value;
|
||||||
|
|
||||||
|
private OPTIONAL() {
|
||||||
|
this.isPresent = false;
|
||||||
|
this.value = EMPTY_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OPTIONAL(KEY_TYPE value) {
|
||||||
|
this.isPresent = true;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OPTIONAL KEY_GENERIC_TYPE empty() {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OPTIONAL KEY_GENERIC_TYPE of(KEY_TYPE value) {
|
||||||
|
return new OPTIONALBRACES(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public KEY_TYPE SUPPLY_GET() {
|
||||||
|
if(!isPresent) throw new NoSuchElementException("No value present");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPresent() {
|
||||||
|
return isPresent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return !isPresent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ifPresent(CONSUMER KEY_GENERIC_TYPE consumer) {
|
||||||
|
if(isPresent) consumer.accept(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ifPresentOrElse(CONSUMER KEY_GENERIC_TYPE action, Runnable emptyAction) {
|
||||||
|
if (isPresent) action.accept(value);
|
||||||
|
else emptyAction.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public KEY_TYPE orElse(KEY_TYPE other) {
|
||||||
|
return isPresent ? value : other;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KEY_TYPE orElseGet(SUPPLIER KEY_GENERIC_TYPE other) {
|
||||||
|
return isPresent ? value : other.SUPPLY_GET();
|
||||||
|
}
|
||||||
|
|
||||||
|
public KEY_TYPE orElseThrow() {
|
||||||
|
if (!isPresent) throw new NoSuchElementException("No value present");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <X extends Throwable> KEY_TYPE orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
|
||||||
|
if(isPresent) return value;
|
||||||
|
else throw exceptionSupplier.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if(obj == this) return true;
|
||||||
|
if(obj instanceof OPTIONAL) {
|
||||||
|
OPTIONAL KEY_GENERIC_TYPE other = (OPTIONAL KEY_GENERIC_TYPE)obj;
|
||||||
|
return (isPresent && other.isPresent ? KEY_EQUALS(value, other.value) : isPresent == other.isPresent);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return isPresent ? KEY_TO_HASH(value) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return isPresent ? "OPTIONAL["+value+"]" : "OPTIONAL.empty";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,6 +7,9 @@ import java.util.Comparator;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
#if IARRAY_FEATURE || TYPE_OBJECT
|
#if IARRAY_FEATURE || TYPE_OBJECT
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@ -33,6 +36,9 @@ import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
|||||||
import speiger.src.collections.PACKAGE.collections.STACK;
|
import speiger.src.collections.PACKAGE.collections.STACK;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
#if !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
@ -682,12 +688,12 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = 0;i<size;i++) {
|
||||||
if(filter.test(data[i])) return data[i];
|
if(filter.test(data[i])) return OPTIONAL.GET_OPTIONAL(data[i]);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -714,7 +720,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -726,7 +732,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, data[i]);
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -8,6 +8,9 @@ import java.util.Collection;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@ -33,6 +36,9 @@ import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
|||||||
import speiger.src.collections.PACKAGE.collections.STACK;
|
import speiger.src.collections.PACKAGE.collections.STACK;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
#if !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
@ -810,13 +816,13 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
KEY_TYPE[] data = this.data;
|
KEY_TYPE[] data = this.data;
|
||||||
for(int i = 0,m=data.length;i<m;i++) {
|
for(int i = 0,m=data.length;i<m;i++) {
|
||||||
if(filter.test(data[i])) return data[i];
|
if(filter.test(data[i])) return OPTIONAL.GET_OPTIONAL(data[i]);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -845,7 +851,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE[] data = this.data;
|
KEY_TYPE[] data = this.data;
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
@ -858,7 +864,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, data[i]);
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -7,6 +7,9 @@ import java.util.Comparator;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@ -27,6 +30,9 @@ import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
|
#if !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
@ -335,12 +341,12 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0,m=data.length;i<m;i++) {
|
for(int i = 0,m=data.length;i<m;i++) {
|
||||||
if(filter.test(data[i])) return data[i];
|
if(filter.test(data[i])) return OPTIONAL.GET_OPTIONAL(data[i]);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -367,7 +373,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -379,7 +385,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, data[i]);
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -4,7 +4,6 @@ package speiger.src.collections.PACKAGE.lists;
|
|||||||
#if DEQUEUE_FEATURE
|
#if DEQUEUE_FEATURE
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
#else if PRIMITIVES
|
#else if PRIMITIVES
|
||||||
import java.nio.JAVA_BUFFER;
|
import java.nio.JAVA_BUFFER;
|
||||||
@ -12,6 +11,9 @@ import java.nio.JAVA_BUFFER;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
#if SPLIT_ITERATOR_FEATURE
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
import java.util.Spliterator;
|
import java.util.Spliterator;
|
||||||
@ -34,6 +36,9 @@ import java.util.function.JAVA_PREDICATE;
|
|||||||
#endif
|
#endif
|
||||||
import java.util.function.JAVA_UNARY_OPERATOR;
|
import java.util.function.JAVA_UNARY_OPERATOR;
|
||||||
#endif
|
#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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
#if !JDK_FUNCTION
|
#if !JDK_FUNCTION
|
||||||
@ -493,12 +498,12 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||||
if(filter.test(entry.value)) return entry.value;
|
if(filter.test(entry.value)) return OPTIONAL.GET_OPTIONAL(entry.value);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -525,7 +530,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -537,7 +542,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, entry.value);
|
state = operator.APPLY_VALUE(state, entry.value);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -4,15 +4,18 @@ import java.util.Arrays;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.locks.StampedLock;
|
import java.util.concurrent.locks.StampedLock;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
#if !TYPE_OBJECT && JDK_TYPE
|
#if !TYPE_OBJECT && JDK_TYPE
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
|
import java.util.OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||||
import java.util.function.VALUE_PREDICATE;
|
import java.util.function.VALUE_PREDICATE;
|
||||||
|
import java.util.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -40,9 +43,12 @@ import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
|||||||
#if !SAME_TYPE
|
#if !SAME_TYPE
|
||||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
|
#if !TYPE_OBJECT && !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#if!VALUE_BOOLEAN
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.CONCURRENT_MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.CONCURRENT_MAP;
|
||||||
@ -78,6 +84,7 @@ import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_C
|
|||||||
#endif
|
#endif
|
||||||
#if !JDK_VALUE
|
#if !JDK_VALUE
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if VALUE_OBJECT
|
#if VALUE_OBJECT
|
||||||
@ -839,7 +846,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -863,11 +870,11 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
seg.unlockRead(stamp);
|
seg.unlockRead(stamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
MapEntry entry = new MapEntry();
|
MapEntry entry = new MapEntry();
|
||||||
for(int i = 0,m=segments.length;i<m;i++) {
|
for(int i = 0,m=segments.length;i<m;i++) {
|
||||||
@ -877,7 +884,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
try {
|
try {
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
entry.set(index, i);
|
entry.set(index, i);
|
||||||
if(filter.test(entry)) return entry;
|
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||||
index = (int)seg.links[index];
|
index = (int)seg.links[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -885,7 +892,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
seg.unlockRead(stamp);
|
seg.unlockRead(stamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1186,7 +1193,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1210,11 +1217,11 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
seg.unlockRead(stamp);
|
seg.unlockRead(stamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0,m=segments.length;i<m;i++) {
|
for(int i = 0,m=segments.length;i<m;i++) {
|
||||||
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
||||||
@ -1222,7 +1229,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
try {
|
try {
|
||||||
int index = seg.firstIndex;
|
int index = seg.firstIndex;
|
||||||
while(index != -1){
|
while(index != -1){
|
||||||
if(filter.test(seg.keys[index])) return seg.keys[index];
|
if(filter.test(seg.keys[index])) return OPTIONAL.GET_OPTIONAL(seg.keys[index]);
|
||||||
index = (int)seg.links[index];
|
index = (int)seg.links[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1230,7 +1237,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
seg.unlockRead(stamp);
|
seg.unlockRead(stamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1454,7 +1461,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
VALUE_TYPE state = EMPTY_VALUE;
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1478,20 +1485,20 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
seg.unlockRead(stamp);
|
seg.unlockRead(stamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_VALUE;
|
if(size() <= 0) return VALUE_OPTIONAL.empty();
|
||||||
for(int i = 0,m=segments.length;i<m;i++) {
|
for(int i = 0,m=segments.length;i<m;i++) {
|
||||||
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
||||||
long stamp = seg.readLock();
|
long stamp = seg.readLock();
|
||||||
try {
|
try {
|
||||||
int index = seg.firstIndex;
|
int index = seg.firstIndex;
|
||||||
while(index != -1){
|
while(index != -1){
|
||||||
if(filter.test(seg.values[index])) return seg.values[index];
|
if(filter.test(seg.values[index])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(seg.values[index]);
|
||||||
index = (int)seg.links[index];
|
index = (int)seg.links[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1499,7 +1506,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
seg.unlockRead(stamp);
|
seg.unlockRead(stamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return VALUE_OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -4,14 +4,17 @@ import java.util.Arrays;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
#if !TYPE_OBJECT && JDK_TYPE
|
#if !TYPE_OBJECT && JDK_TYPE
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
|
import java.util.OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||||
import java.util.function.VALUE_PREDICATE;
|
import java.util.function.VALUE_PREDICATE;
|
||||||
|
import java.util.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
@ -27,6 +30,7 @@ import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
|
|||||||
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT && !JDK_TYPE
|
#if !TYPE_OBJECT && !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_INT || !SAME_TYPE
|
#if !TYPE_INT || !SAME_TYPE
|
||||||
@ -59,6 +63,7 @@ import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_C
|
|||||||
#endif
|
#endif
|
||||||
#if !JDK_VALUE
|
#if !JDK_VALUE
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -873,7 +878,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -888,21 +893,21 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
state = operator.apply(state, new ValueMapEntry(index));
|
state = operator.apply(state, new ValueMapEntry(index));
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return null;
|
if(size() <= 0) return Optional.empty();
|
||||||
MapEntry entry = new MapEntry();
|
MapEntry entry = new MapEntry();
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
entry.set(index);
|
entry.set(index);
|
||||||
if(filter.test(entry)) return entry;
|
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1160,7 +1165,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1175,19 +1180,19 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_KEY_VALUE;
|
if(size() <= 0) return OPTIONAL.empty();
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1){
|
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];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1343,7 +1348,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
VALUE_TYPE state = EMPTY_VALUE;
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1358,19 +1363,19 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
state = operator.APPLY_VALUE(state, values[index]);
|
state = operator.APPLY_VALUE(state, values[index]);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_VALUE;
|
if(size() <= 0) return VALUE_OPTIONAL.empty();
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1){
|
while(index != -1){
|
||||||
if(filter.test(values[index])) return values[index];
|
if(filter.test(values[index])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[index]);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return VALUE_OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -5,14 +5,17 @@ import java.util.ConcurrentModificationException;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
#if !TYPE_OBJECT && JDK_TYPE
|
#if !TYPE_OBJECT && JDK_TYPE
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
|
import java.util.OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||||
import java.util.function.VALUE_PREDICATE;
|
import java.util.function.VALUE_PREDICATE;
|
||||||
|
import java.util.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -37,9 +40,12 @@ import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
|||||||
#if !SAME_TYPE
|
#if !SAME_TYPE
|
||||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
|
#if !TYPE_OBJECT && !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#if !VALUE_BOOLEAN
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -75,6 +81,7 @@ import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_C
|
|||||||
#endif
|
#endif
|
||||||
#if !JDK_VALUE
|
#if !JDK_VALUE
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||||
@ -1090,7 +1097,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1107,25 +1114,25 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
}
|
}
|
||||||
state = operator.apply(state, new ValueMapEntry(i));
|
state = operator.apply(state, new ValueMapEntry(i));
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return null;
|
if(size() <= 0) return Optional.empty();
|
||||||
MapEntry entry = new MapEntry();
|
MapEntry entry = new MapEntry();
|
||||||
if(containsNull) {
|
if(containsNull) {
|
||||||
entry.set(nullIndex);
|
entry.set(nullIndex);
|
||||||
if(filter.test(entry)) return entry;
|
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||||
}
|
}
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) {
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) {
|
||||||
entry.set(i);
|
entry.set(i);
|
||||||
if(filter.test(entry)) return entry;
|
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1331,7 +1338,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1348,18 +1355,18 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_KEY_VALUE;
|
if(size() <= 0) return OPTIONAL.empty();
|
||||||
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
|
if(containsNull && filter.test(keys[nullIndex])) return OPTIONAL.GET_OPTIONAL(keys[nullIndex]);
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) return keys[i];
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) return OPTIONAL.GET_OPTIONAL(keys[i]);
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1497,7 +1504,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
VALUE_TYPE state = EMPTY_VALUE;
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1514,18 +1521,18 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, values[i]);
|
state = operator.APPLY_VALUE(state, values[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_VALUE;
|
if(size() <= 0) return VALUE_OPTIONAL.empty();
|
||||||
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
|
if(containsNull && filter.test(values[nullIndex])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[nullIndex]);
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(values[i])) return values[i];
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(values[i])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[i]);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return VALUE_OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -4,14 +4,17 @@ import java.util.Arrays;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
#if !TYPE_OBJECT && JDK_TYPE
|
#if !TYPE_OBJECT && JDK_TYPE
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
|
import java.util.OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||||
import java.util.function.VALUE_PREDICATE;
|
import java.util.function.VALUE_PREDICATE;
|
||||||
|
import java.util.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
@ -27,6 +30,7 @@ import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
|
|||||||
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT && !JDK_TYPE
|
#if !TYPE_OBJECT && !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_INT || !SAME_TYPE
|
#if !TYPE_INT || !SAME_TYPE
|
||||||
@ -58,6 +62,7 @@ import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_C
|
|||||||
#endif
|
#endif
|
||||||
#if !JDK_VALUE
|
#if !JDK_VALUE
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -877,7 +882,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -892,21 +897,21 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
state = operator.apply(state, new ValueMapEntry(index));
|
state = operator.apply(state, new ValueMapEntry(index));
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return null;
|
if(size() <= 0) return Optional.empty();
|
||||||
MapEntry entry = new MapEntry();
|
MapEntry entry = new MapEntry();
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
entry.set(index);
|
entry.set(index);
|
||||||
if(filter.test(entry)) return entry;
|
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1159,7 +1164,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1174,19 +1179,19 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_KEY_VALUE;
|
if(size() <= 0) return OPTIONAL.empty();
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1){
|
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];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1344,7 +1349,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
VALUE_TYPE state = EMPTY_VALUE;
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1359,19 +1364,19 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
state = operator.APPLY_VALUE(state, values[index]);
|
state = operator.APPLY_VALUE(state, values[index]);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_VALUE;
|
if(size() <= 0) return VALUE_OPTIONAL.empty();
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1){
|
while(index != -1){
|
||||||
if(filter.test(values[index])) return values[index];
|
if(filter.test(values[index])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[index]);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return VALUE_OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -5,14 +5,17 @@ import java.util.ConcurrentModificationException;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
#if !TYPE_OBJECT && JDK_TYPE
|
#if !TYPE_OBJECT && JDK_TYPE
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
|
import java.util.OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||||
import java.util.function.VALUE_PREDICATE;
|
import java.util.function.VALUE_PREDICATE;
|
||||||
|
import java.util.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -37,9 +40,12 @@ import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
|||||||
#if !SAME_TYPE
|
#if !SAME_TYPE
|
||||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
|
#if !TYPE_OBJECT && !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#if !VALUE_BOOLEAN
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -73,6 +79,7 @@ import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_C
|
|||||||
|
|
||||||
#if !JDK_VALUE
|
#if !JDK_VALUE
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||||
@ -1049,7 +1056,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1066,25 +1073,25 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
}
|
}
|
||||||
state = operator.apply(state, new ValueMapEntry(i));
|
state = operator.apply(state, new ValueMapEntry(i));
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return null;
|
if(size() <= 0) return Optional.empty();
|
||||||
MapEntry entry = new MapEntry();
|
MapEntry entry = new MapEntry();
|
||||||
if(containsNull) {
|
if(containsNull) {
|
||||||
entry.set(nullIndex);
|
entry.set(nullIndex);
|
||||||
if(filter.test(entry)) return entry;
|
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||||
}
|
}
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i])) {
|
if(KEY_EQUALS_NOT_NULL(keys[i])) {
|
||||||
entry.set(i);
|
entry.set(i);
|
||||||
if(filter.test(entry)) return entry;
|
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1286,7 +1293,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1303,18 +1310,18 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_KEY_VALUE;
|
if(size() <= 0) return OPTIONAL.empty();
|
||||||
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
|
if(containsNull && filter.test(keys[nullIndex])) return OPTIONAL.GET_OPTIONAL(keys[nullIndex]);
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) return keys[i];
|
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) return OPTIONAL.GET_OPTIONAL(keys[i]);
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1452,7 +1459,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
VALUE_TYPE state = EMPTY_VALUE;
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1469,18 +1476,18 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, values[i]);
|
state = operator.APPLY_VALUE(state, values[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_VALUE;
|
if(size() <= 0) return VALUE_OPTIONAL.empty();
|
||||||
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
|
if(containsNull && filter.test(values[nullIndex])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[nullIndex]);
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(values[i])) return values[i];
|
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(values[i])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[i]);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return VALUE_OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -4,14 +4,17 @@ import java.util.Arrays;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
#if !TYPE_OBJECT && JDK_TYPE
|
#if !TYPE_OBJECT && JDK_TYPE
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
|
import java.util.OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||||
import java.util.function.VALUE_PREDICATE;
|
import java.util.function.VALUE_PREDICATE;
|
||||||
|
import java.util.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -26,9 +29,12 @@ import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
|
|||||||
#if !SAME_TYPE && !TYPE_INT
|
#if !SAME_TYPE && !TYPE_INT
|
||||||
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
|
#if !TYPE_OBJECT && !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#if !VALUE_BOOLEAN
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#if !TYPE_INT || !SAME_TYPE
|
#if !TYPE_INT || !SAME_TYPE
|
||||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
@ -59,6 +65,7 @@ import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_C
|
|||||||
#endif
|
#endif
|
||||||
#if !JDK_VALUE
|
#if !JDK_VALUE
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -783,7 +790,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -798,21 +805,21 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return null;
|
if(size() <= 0) return Optional.empty();
|
||||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
entry.set(keys[index], values[index]);
|
entry.set(keys[index], values[index]);
|
||||||
if(filter.test(entry)) return entry;
|
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1037,7 +1044,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1052,19 +1059,19 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_KEY_VALUE;
|
if(size() <= 0) return OPTIONAL.empty();
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1){
|
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];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1213,7 +1220,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
VALUE_TYPE state = EMPTY_VALUE;
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1228,19 +1235,19 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
state = operator.APPLY_VALUE(state, values[index]);
|
state = operator.APPLY_VALUE(state, values[index]);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_VALUE;
|
if(size() <= 0) return VALUE_OPTIONAL.empty();
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1){
|
while(index != -1){
|
||||||
if(filter.test(values[index])) return values[index];
|
if(filter.test(values[index])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[index]);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return VALUE_OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -4,14 +4,17 @@ import java.util.Arrays;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
#if !TYPE_OBJECT && JDK_TYPE
|
#if !TYPE_OBJECT && JDK_TYPE
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
|
import java.util.OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||||
import java.util.function.VALUE_PREDICATE;
|
import java.util.function.VALUE_PREDICATE;
|
||||||
|
import java.util.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
@ -26,9 +29,12 @@ import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
|
|||||||
#if !SAME_TYPE && !TYPE_INT
|
#if !SAME_TYPE && !TYPE_INT
|
||||||
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
|
#if !TYPE_OBJECT && !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#if!VALUE_BOOLEAN
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#if !TYPE_INT || !SAME_TYPE
|
#if !TYPE_INT || !SAME_TYPE
|
||||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
@ -66,6 +72,7 @@ import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_C
|
|||||||
#endif
|
#endif
|
||||||
#if !JDK_VALUE
|
#if !JDK_VALUE
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if !VALUE_OBJECT
|
#if !VALUE_OBJECT
|
||||||
@ -1009,7 +1016,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1021,19 +1028,19 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
}
|
}
|
||||||
state = operator.apply(state, new ValueMapEntry(i));
|
state = operator.apply(state, new ValueMapEntry(i));
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return null;
|
if(size() <= 0) return Optional.empty();
|
||||||
MapEntry entry = new MapEntry();
|
MapEntry entry = new MapEntry();
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = 0;i<size;i++) {
|
||||||
entry.set(i);
|
entry.set(i);
|
||||||
if(filter.test(entry)) return entry;
|
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1218,7 +1225,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1230,16 +1237,16 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = 0;i<size;i++) {
|
||||||
if(filter.test(keys[i])) return keys[i];
|
if(filter.test(keys[i])) return OPTIONAL.GET_OPTIONAL(keys[i]);
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1359,7 +1366,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
VALUE_TYPE state = EMPTY_VALUE;
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1371,16 +1378,16 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, values[i]);
|
state = operator.APPLY_VALUE(state, values[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = 0;i<size;i++) {
|
||||||
if(filter.test(values[i])) return values[i];
|
if(filter.test(values[i])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[i]);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return VALUE_OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -6,15 +6,18 @@ import java.util.Map;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
#if !TYPE_OBJECT && JDK_TYPE
|
#if !TYPE_OBJECT && JDK_TYPE
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
|
import java.util.OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||||
import java.util.function.VALUE_PREDICATE;
|
import java.util.function.VALUE_PREDICATE;
|
||||||
|
import java.util.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -37,9 +40,12 @@ import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
|||||||
#if !TYPE_INT || !SAME_TYPE
|
#if !TYPE_INT || !SAME_TYPE
|
||||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
|
#if !TYPE_OBJECT && !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#if!VALUE_BOOLEAN
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
#if !SAME_TYPE
|
#if !SAME_TYPE
|
||||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||||
@ -73,6 +79,7 @@ import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_C
|
|||||||
#endif
|
#endif
|
||||||
#if !JDK_VALUE
|
#if !JDK_VALUE
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||||
@ -1323,7 +1330,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1335,15 +1342,15 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_KEY_VALUE(state, entry.key);
|
state = operator.APPLY_KEY_VALUE(state, entry.key);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||||
if(filter.test(entry.key)) return entry.key;
|
if(filter.test(entry.key)) return OPTIONAL.GET_OPTIONAL(entry.key);
|
||||||
return EMPTY_KEY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -2026,7 +2033,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -2038,19 +2045,19 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
}
|
}
|
||||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return null;
|
if(size() <= 0) return Optional.empty();
|
||||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||||
subEntry.set(entry.key, entry.value);
|
subEntry.set(entry.key, entry.value);
|
||||||
if(filter.test(subEntry)) return subEntry;
|
if(filter.test(subEntry)) return Optional.ofNullable(subEntry);
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -2165,7 +2172,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
VALUE_TYPE state = EMPTY_VALUE;
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -2177,15 +2184,15 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, entry.value);
|
state = operator.APPLY_VALUE(state, entry.value);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||||
if(filter.test(entry.value)) return entry.value;
|
if(filter.test(entry.value)) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(entry.value);
|
||||||
return EMPTY_VALUE;
|
return VALUE_OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -2521,7 +2528,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
VALUE_TYPE state = EMPTY_VALUE;
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -2533,15 +2540,15 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, entry.value);
|
state = operator.APPLY_VALUE(state, entry.value);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||||
if(filter.test(entry.value)) return entry.value;
|
if(filter.test(entry.value)) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(entry.value);
|
||||||
return EMPTY_VALUE;
|
return VALUE_OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -2687,7 +2694,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -2699,19 +2706,19 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
}
|
}
|
||||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return null;
|
if(size() <= 0) return Optional.empty();
|
||||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||||
subEntry.set(entry.key, entry.value);
|
subEntry.set(entry.key, entry.value);
|
||||||
if(filter.test(subEntry)) return subEntry;
|
if(filter.test(subEntry)) return Optional.ofNullable(subEntry);
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -6,15 +6,18 @@ import java.util.Map;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
#if !TYPE_OBJECT && JDK_TYPE
|
#if !TYPE_OBJECT && JDK_TYPE
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
|
import java.util.OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||||
import java.util.function.VALUE_PREDICATE;
|
import java.util.function.VALUE_PREDICATE;
|
||||||
|
import java.util.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
@ -36,9 +39,12 @@ import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
|||||||
#if !TYPE_INT || !SAME_TYPE
|
#if !TYPE_INT || !SAME_TYPE
|
||||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
|
#if !TYPE_OBJECT && !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#if!VALUE_BOOLEAN
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
#if !SAME_TYPE
|
#if !SAME_TYPE
|
||||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||||
@ -72,6 +78,7 @@ import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_C
|
|||||||
#endif
|
#endif
|
||||||
#if !JDK_VALUE
|
#if !JDK_VALUE
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||||
@ -1379,7 +1386,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1391,15 +1398,15 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_KEY_VALUE(state, entry.key);
|
state = operator.APPLY_KEY_VALUE(state, entry.key);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||||
if(filter.test(entry.key)) return entry.key;
|
if(filter.test(entry.key)) return OPTIONAL.GET_OPTIONAL(entry.key);
|
||||||
return EMPTY_KEY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -2092,7 +2099,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -2104,19 +2111,19 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
}
|
}
|
||||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return null;
|
if(size() <= 0) return Optional.empty();
|
||||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||||
subEntry.set(entry.key, entry.value);
|
subEntry.set(entry.key, entry.value);
|
||||||
if(filter.test(subEntry)) return subEntry;
|
if(filter.test(subEntry)) return Optional.ofNullable(subEntry);
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -2231,7 +2238,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
VALUE_TYPE state = EMPTY_VALUE;
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -2243,15 +2250,15 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, entry.value);
|
state = operator.APPLY_VALUE(state, entry.value);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||||
if(filter.test(entry.value)) return entry.value;
|
if(filter.test(entry.value)) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(entry.value);
|
||||||
return EMPTY_VALUE;
|
return VALUE_OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -2587,7 +2594,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
VALUE_TYPE state = EMPTY_VALUE;
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -2599,15 +2606,15 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, entry.value);
|
state = operator.APPLY_VALUE(state, entry.value);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||||
if(filter.test(entry.value)) return entry.value;
|
if(filter.test(entry.value)) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(entry.value);
|
||||||
return EMPTY_VALUE;
|
return VALUE_OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -2753,7 +2760,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
Objects.requireNonNull(operator);
|
Objects.requireNonNull(operator);
|
||||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -2765,19 +2772,19 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
}
|
}
|
||||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return null;
|
if(size() <= 0) return Optional.empty();
|
||||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||||
subEntry.set(entry.key, entry.value);
|
subEntry.set(entry.key, entry.value);
|
||||||
if(filter.test(subEntry)) return subEntry;
|
if(filter.test(subEntry)) return Optional.ofNullable(subEntry);
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -7,12 +7,18 @@ import java.util.function.Consumer;
|
|||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
#if JDK_FUNCTION
|
#if JDK_FUNCTION
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
#if !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
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
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0,m=size();i<m;i++) {
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
int index = (first + i) % array.length;
|
int index = (first + i) % array.length;
|
||||||
if(filter.test(array[index])) {
|
if(filter.test(array[index])) {
|
||||||
KEY_TYPE data = array[index];
|
KEY_TYPE data = array[index];
|
||||||
removeIndex(index);
|
removeIndex(index);
|
||||||
return data;
|
return OPTIONAL.GET_OPTIONAL(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -355,7 +361,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
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]);
|
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -8,12 +8,18 @@ import java.util.function.Consumer;
|
|||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if JDK_FUNCTION
|
#if JDK_FUNCTION
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
#if !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
@ -346,7 +352,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -358,20 +364,20 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, array[i]);
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = 0;i<size;i++) {
|
||||||
if(filter.test(array[i])) {
|
if(filter.test(array[i])) {
|
||||||
KEY_TYPE data = array[i];
|
KEY_TYPE data = array[i];
|
||||||
removeIndex(i);
|
removeIndex(i);
|
||||||
return data;
|
return OPTIONAL.GET_OPTIONAL(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -8,12 +8,18 @@ import java.util.function.Consumer;
|
|||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if JDK_FUNCTION
|
#if JDK_FUNCTION
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
#if !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
@ -326,7 +332,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -338,20 +344,20 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, array[i]);
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = 0;i<size;i++) {
|
||||||
if(filter.test(array[i])) {
|
if(filter.test(array[i])) {
|
||||||
KEY_TYPE data = array[i];
|
KEY_TYPE data = array[i];
|
||||||
removeIndex(i);
|
removeIndex(i);
|
||||||
return data;
|
return OPTIONAL.GET_OPTIONAL(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -10,6 +10,9 @@ import java.util.function.BiFunction;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if JDK_FUNCTION
|
#if JDK_FUNCTION
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
@ -19,6 +22,9 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
|||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
#if !JDK_FUNCTION
|
#if !JDK_FUNCTION
|
||||||
@ -405,12 +411,12 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||||
if(filter.test(entry.key)) return entry.key;
|
if(filter.test(entry.key)) return OPTIONAL.GET_OPTIONAL(entry.key);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -437,7 +443,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -449,7 +455,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, entry.key);
|
state = operator.APPLY_VALUE(state, entry.key);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1314,7 +1320,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1326,16 +1332,16 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, entry.key);
|
state = operator.APPLY_VALUE(state, entry.key);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||||
if(filter.test(entry.key)) return entry.key;
|
if(filter.test(entry.key)) return OPTIONAL.GET_OPTIONAL(entry.key);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -8,6 +8,9 @@ import java.util.function.BiFunction;
|
|||||||
#endif
|
#endif
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
#if JDK_FUNCTION
|
#if JDK_FUNCTION
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
@ -18,7 +21,9 @@ import java.util.function.JAVA_PREDICATE;
|
|||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
#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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
#if !JDK_FUNCTION
|
#if !JDK_FUNCTION
|
||||||
@ -438,12 +443,12 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = 0;i<size;i++) {
|
||||||
if(filter.test(data[i])) return data[i];
|
if(filter.test(data[i])) return OPTIONAL.GET_OPTIONAL(data[i]);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@ -470,7 +475,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -482,7 +487,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, data[i]);
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -9,6 +9,9 @@ import java.util.Collection;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if JDK_FUNCTION
|
#if JDK_FUNCTION
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
@ -19,6 +22,9 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
#if !JDK_FUNCTION
|
#if !JDK_FUNCTION
|
||||||
@ -414,7 +420,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
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]);
|
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
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];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -9,6 +9,9 @@ import java.util.Objects;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if JDK_FUNCTION
|
#if JDK_FUNCTION
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
@ -18,6 +21,9 @@ import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
|||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
|
#if !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
@ -656,7 +662,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -669,18 +675,18 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
else state = operator.APPLY_VALUE(state, keys[index]);
|
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
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];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -5,6 +5,9 @@ import java.util.Collection;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
@ -21,6 +24,9 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
#if !JDK_FUNCTION
|
#if !JDK_FUNCTION
|
||||||
@ -511,7 +517,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
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]);
|
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
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];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -6,6 +6,9 @@ import java.util.ConcurrentModificationException;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
@ -16,6 +19,9 @@ import java.util.function.PREDICATE;
|
|||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
#if !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
@ -635,7 +641,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -652,18 +658,18 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, keys[i]);
|
state = operator.APPLY_VALUE(state, keys[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_VALUE;
|
if(size() <= 0) return OPTIONAL.empty();
|
||||||
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
|
if(containsNull && filter.test(keys[nullIndex])) return OPTIONAL.GET_OPTIONAL(keys[nullIndex]);
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) return keys[i];
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) return OPTIONAL.GET_OPTIONAL(keys[i]);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -6,6 +6,9 @@ import java.util.ConcurrentModificationException;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
@ -20,6 +23,9 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
|||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
#if !JDK_FUNCTION
|
#if !JDK_FUNCTION
|
||||||
@ -498,7 +504,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -515,18 +521,18 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, keys[i]);
|
state = operator.APPLY_VALUE(state, keys[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_VALUE;
|
if(size() <= 0) return OPTIONAL.empty();
|
||||||
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
|
if(containsNull && filter.test(keys[nullIndex])) return OPTIONAL.GET_OPTIONAL(keys[nullIndex]);
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) return keys[i];
|
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) return OPTIONAL.GET_OPTIONAL(keys[i]);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -2,6 +2,9 @@ package speiger.src.collections.PACKAGE.sets;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@ -19,6 +22,9 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
|||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
#if !JDK_FUNCTION
|
#if !JDK_FUNCTION
|
||||||
@ -427,7 +433,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -439,16 +445,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, entry.key);
|
state = operator.APPLY_VALUE(state, entry.key);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||||
if(filter.test(entry.key)) return entry.key;
|
if(filter.test(entry.key)) return OPTIONAL.GET_OPTIONAL(entry.key);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1374,7 +1380,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@ -1386,16 +1392,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, entry.key);
|
state = operator.APPLY_VALUE(state, entry.key);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||||
if(filter.test(entry.key)) return entry.key;
|
if(filter.test(entry.key)) return OPTIONAL.GET_OPTIONAL(entry.key);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return OPTIONAL.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -8,6 +8,9 @@ import java.util.ConcurrentModificationException;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
@ -30,6 +33,9 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#endif
|
#endif
|
||||||
|
#if !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
@ -869,9 +875,9 @@ public class COLLECTIONS
|
|||||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return c.reduce(identity, operator); } }
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return c.reduce(identity, operator); } }
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return c.reduce(operator); } }
|
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return c.reduce(operator); } }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.findFirst(filter); } }
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.findFirst(filter); } }
|
||||||
@Override
|
@Override
|
||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.count(filter); } }
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.count(filter); } }
|
||||||
}
|
}
|
||||||
@ -1021,9 +1027,9 @@ public class COLLECTIONS
|
|||||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { return c.reduce(identity, operator); }
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { return c.reduce(identity, operator); }
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { return c.reduce(operator); }
|
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { return c.reduce(operator); }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { return c.findFirst(filter); }
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { return c.findFirst(filter); }
|
||||||
@Override
|
@Override
|
||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { return c.count(filter); }
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) { return c.count(filter); }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,16 +4,22 @@ package speiger.src.collections.PACKAGE.utils;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
#if JDK_FUNCTION
|
#if JDK_FUNCTION
|
||||||
import java.util.function.PREDICATE;
|
import java.util.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#endif
|
#endif
|
||||||
|
#if !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if DEQUEUE_FEATURE
|
#if DEQUEUE_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
|
import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
|
||||||
#endif
|
#endif
|
||||||
@ -24,6 +30,7 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
|||||||
#if !JDK_FUNCTION
|
#if !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,7 +147,15 @@ public class PRIORITY_QUEUES
|
|||||||
@Override
|
@Override
|
||||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.matchesAll(filter); } }
|
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.matchesAll(filter); } }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.findFirst(filter); } }
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.findFirst(filter); } }
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) { synchronized(mutex) { return queue.reduce(identity, operator); } }
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return queue.reduce(identity, operator); } }
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return queue.reduce(operator); } }
|
||||||
@Override
|
@Override
|
||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.count(filter); } }
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.count(filter); } }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,15 @@ public class FILE_KEY_TYPECollectionForEachTester KEY_GENERIC_TYPE extends ABSTR
|
|||||||
HELPERS.assertContentsAnyOrder(elements, createSamplesArray());
|
HELPERS.assertContentsAnyOrder(elements, createSamplesArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ignore
|
||||||
|
@CollectionFeature.Require(absent = KNOWN_ORDER)
|
||||||
|
public void testIndexedForEachUnknownOrder() {
|
||||||
|
#endignore
|
||||||
|
LIST KEY_GENERIC_TYPE elements = new ARRAY_LISTBRACES();
|
||||||
|
collection.forEachIndexed((K, V) -> elements.add(V));
|
||||||
|
HELPERS.assertContentsAnyOrder(elements, createSamplesArray());
|
||||||
|
}
|
||||||
|
|
||||||
#ignore
|
#ignore
|
||||||
@CollectionFeature.Require(absent = KNOWN_ORDER)
|
@CollectionFeature.Require(absent = KNOWN_ORDER)
|
||||||
public void testForEachExtraUnknownOrder() {
|
public void testForEachExtraUnknownOrder() {
|
||||||
@ -44,6 +53,15 @@ public class FILE_KEY_TYPECollectionForEachTester KEY_GENERIC_TYPE extends ABSTR
|
|||||||
assertEquals("Different ordered iteration", HELPERS.copyToList(getOrderedElements()), elements);
|
assertEquals("Different ordered iteration", HELPERS.copyToList(getOrderedElements()), elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ignore
|
||||||
|
@CollectionFeature.Require(KNOWN_ORDER)
|
||||||
|
public void testIndexedForEachKnownOrder() {
|
||||||
|
#endignore
|
||||||
|
LIST KEY_GENERIC_TYPE elements = new ARRAY_LISTBRACES();
|
||||||
|
collection.forEachIndexed((K, V) -> elements.add(V));
|
||||||
|
assertEquals("Different ordered iteration", HELPERS.copyToList(getOrderedElements()), elements);
|
||||||
|
}
|
||||||
|
|
||||||
#ignore
|
#ignore
|
||||||
@CollectionFeature.Require(KNOWN_ORDER)
|
@CollectionFeature.Require(KNOWN_ORDER)
|
||||||
public void testForEachExtraKnownOrder() {
|
public void testForEachExtraKnownOrder() {
|
||||||
|
|||||||
@ -4,6 +4,12 @@ package speiger.src.testers.PACKAGE.tests.iterable;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#else
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#endif
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
|
|
||||||
import com.google.common.collect.testing.features.CollectionSize;
|
import com.google.common.collect.testing.features.CollectionSize;
|
||||||
@ -27,17 +33,17 @@ public class FILE_KEY_TYPEIterableFindFirstTester KEY_GENERIC_TYPE extends ABSTR
|
|||||||
@CollectionSize.Require(absent = CollectionSize.ZERO)
|
@CollectionSize.Require(absent = CollectionSize.ZERO)
|
||||||
#endignore
|
#endignore
|
||||||
public void testIterableFindFirst_FindFirstElements() {
|
public void testIterableFindFirst_FindFirstElements() {
|
||||||
assertEquals("First Element should be found", e0(), container.findFirst(T -> KEY_EQUALS(T, e0())));
|
assertEquals("First Element should be found", e0(), container.findFirst(T -> KEY_EQUALS(T, e0())).SUPPLY_GET());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIterableFindFirst_FindNothing() {
|
public void testIterableFindFirst_FindNothing() {
|
||||||
assertEquals("No element should be found", EMPTY_KEY_VALUE, container.findFirst(T -> KEY_EQUALS(T, e4())));
|
assertEquals("No element should be found", OPTIONAL.empty(), container.findFirst(T -> KEY_EQUALS(T, e4())));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ignore
|
#ignore
|
||||||
@CollectionSize.Require(CollectionSize.SEVERAL)
|
@CollectionSize.Require(CollectionSize.SEVERAL)
|
||||||
#endignore
|
#endignore
|
||||||
public void testIterableFindFirst_FindLastElement() {
|
public void testIterableFindFirst_FindLastElement() {
|
||||||
assertEquals("Last Element should be found", e2(), container.findFirst(T -> KEY_EQUALS(T, e2())));
|
assertEquals("Last Element should be found", e2(), container.findFirst(T -> KEY_EQUALS(T, e2())).SUPPLY_GET());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,9 +3,16 @@ package speiger.src.testers.PACKAGE.tests.iterable;
|
|||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#else
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
#endif
|
#endif
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.features.CollectionSize;
|
||||||
|
|
||||||
import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER;
|
import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER;
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@ -29,7 +36,7 @@ public class FILE_KEY_TYPEIterableReduceTester KEY_GENERIC_TYPE extends ABSTRACT
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testIterableReduce() {
|
public void testIterableReduce() {
|
||||||
assertEquals("The sum of the collection should match", getSum(), collection.reduce(this::sum));
|
assertEquals("The sum of the collection should match", size == CollectionSize.ZERO ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(getSum()), collection.reduce(this::sum));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIterableExtraReduce() {
|
public void testIterableExtraReduce() {
|
||||||
|
|||||||
@ -0,0 +1,89 @@
|
|||||||
|
package speiger.src.collections.booleans.functions;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public final class OptionalBoolean {
|
||||||
|
private static final OptionalBoolean EMPTY = new OptionalBoolean();
|
||||||
|
|
||||||
|
private final boolean isPresent;
|
||||||
|
private final boolean value;
|
||||||
|
|
||||||
|
private OptionalBoolean() {
|
||||||
|
this.isPresent = false;
|
||||||
|
this.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OptionalBoolean(boolean value) {
|
||||||
|
this.isPresent = true;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OptionalBoolean empty() {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OptionalBoolean of(boolean value) {
|
||||||
|
return new OptionalBoolean(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getAsBoolean() {
|
||||||
|
if(!isPresent) throw new NoSuchElementException("No value present");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPresent() {
|
||||||
|
return isPresent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return !isPresent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ifPresent(BooleanConsumer consumer) {
|
||||||
|
if(isPresent) consumer.accept(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ifPresentOrElse(BooleanConsumer action, Runnable emptyAction) {
|
||||||
|
if (isPresent) action.accept(value);
|
||||||
|
else emptyAction.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean orElse(boolean other) {
|
||||||
|
return isPresent ? value : other;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean orElseGet(BooleanSupplier other) {
|
||||||
|
return isPresent ? value : other.getAsBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean orElseThrow() {
|
||||||
|
if (!isPresent) throw new NoSuchElementException("No value present");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <X extends Throwable> boolean orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
|
||||||
|
if(isPresent) return value;
|
||||||
|
else throw exceptionSupplier.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if(obj == this) return true;
|
||||||
|
if(obj instanceof OptionalBoolean) {
|
||||||
|
OptionalBoolean other = (OptionalBoolean)obj;
|
||||||
|
return (isPresent && other.isPresent ? value == other.value : isPresent == other.isPresent);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return isPresent ? Boolean.hashCode(value) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return isPresent ? "OptionalBoolean["+value+"]" : "OptionalBoolean.empty";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
package speiger.src.collections.bytes.functions;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public final class OptionalByte {
|
||||||
|
private static final OptionalByte EMPTY = new OptionalByte();
|
||||||
|
|
||||||
|
private final boolean isPresent;
|
||||||
|
private final byte value;
|
||||||
|
|
||||||
|
private OptionalByte() {
|
||||||
|
this.isPresent = false;
|
||||||
|
this.value = (byte)0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OptionalByte(byte value) {
|
||||||
|
this.isPresent = true;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OptionalByte empty() {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OptionalByte of(byte value) {
|
||||||
|
return new OptionalByte(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte getAsByte() {
|
||||||
|
if(!isPresent) throw new NoSuchElementException("No value present");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPresent() {
|
||||||
|
return isPresent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return !isPresent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ifPresent(ByteConsumer consumer) {
|
||||||
|
if(isPresent) consumer.accept(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ifPresentOrElse(ByteConsumer action, Runnable emptyAction) {
|
||||||
|
if (isPresent) action.accept(value);
|
||||||
|
else emptyAction.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte orElse(byte other) {
|
||||||
|
return isPresent ? value : other;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte orElseGet(ByteSupplier other) {
|
||||||
|
return isPresent ? value : other.getAsByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte orElseThrow() {
|
||||||
|
if (!isPresent) throw new NoSuchElementException("No value present");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <X extends Throwable> byte orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
|
||||||
|
if(isPresent) return value;
|
||||||
|
else throw exceptionSupplier.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if(obj == this) return true;
|
||||||
|
if(obj instanceof OptionalByte) {
|
||||||
|
OptionalByte other = (OptionalByte)obj;
|
||||||
|
return (isPresent && other.isPresent ? value == other.value : isPresent == other.isPresent);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return isPresent ? Byte.hashCode(value) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return isPresent ? "OptionalByte["+value+"]" : "OptionalByte.empty";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
package speiger.src.collections.chars.functions;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public final class OptionalChar {
|
||||||
|
private static final OptionalChar EMPTY = new OptionalChar();
|
||||||
|
|
||||||
|
private final boolean isPresent;
|
||||||
|
private final char value;
|
||||||
|
|
||||||
|
private OptionalChar() {
|
||||||
|
this.isPresent = false;
|
||||||
|
this.value = (char)0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OptionalChar(char value) {
|
||||||
|
this.isPresent = true;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OptionalChar empty() {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OptionalChar of(char value) {
|
||||||
|
return new OptionalChar(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public char getAsChar() {
|
||||||
|
if(!isPresent) throw new NoSuchElementException("No value present");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPresent() {
|
||||||
|
return isPresent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return !isPresent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ifPresent(CharConsumer consumer) {
|
||||||
|
if(isPresent) consumer.accept(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ifPresentOrElse(CharConsumer action, Runnable emptyAction) {
|
||||||
|
if (isPresent) action.accept(value);
|
||||||
|
else emptyAction.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public char orElse(char other) {
|
||||||
|
return isPresent ? value : other;
|
||||||
|
}
|
||||||
|
|
||||||
|
public char orElseGet(CharSupplier other) {
|
||||||
|
return isPresent ? value : other.getAsChar();
|
||||||
|
}
|
||||||
|
|
||||||
|
public char orElseThrow() {
|
||||||
|
if (!isPresent) throw new NoSuchElementException("No value present");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <X extends Throwable> char orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
|
||||||
|
if(isPresent) return value;
|
||||||
|
else throw exceptionSupplier.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if(obj == this) return true;
|
||||||
|
if(obj instanceof OptionalChar) {
|
||||||
|
OptionalChar other = (OptionalChar)obj;
|
||||||
|
return (isPresent && other.isPresent ? value == other.value : isPresent == other.isPresent);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return isPresent ? Character.hashCode(value) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return isPresent ? "OptionalChar["+value+"]" : "OptionalChar.empty";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
package speiger.src.collections.floats.functions;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public final class OptionalFloat {
|
||||||
|
private static final OptionalFloat EMPTY = new OptionalFloat();
|
||||||
|
|
||||||
|
private final boolean isPresent;
|
||||||
|
private final float value;
|
||||||
|
|
||||||
|
private OptionalFloat() {
|
||||||
|
this.isPresent = false;
|
||||||
|
this.value = 0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OptionalFloat(float value) {
|
||||||
|
this.isPresent = true;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OptionalFloat empty() {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OptionalFloat of(float value) {
|
||||||
|
return new OptionalFloat(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getAsFloat() {
|
||||||
|
if(!isPresent) throw new NoSuchElementException("No value present");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPresent() {
|
||||||
|
return isPresent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return !isPresent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ifPresent(FloatConsumer consumer) {
|
||||||
|
if(isPresent) consumer.accept(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ifPresentOrElse(FloatConsumer action, Runnable emptyAction) {
|
||||||
|
if (isPresent) action.accept(value);
|
||||||
|
else emptyAction.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public float orElse(float other) {
|
||||||
|
return isPresent ? value : other;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float orElseGet(FloatSupplier other) {
|
||||||
|
return isPresent ? value : other.getAsFloat();
|
||||||
|
}
|
||||||
|
|
||||||
|
public float orElseThrow() {
|
||||||
|
if (!isPresent) throw new NoSuchElementException("No value present");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <X extends Throwable> float orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
|
||||||
|
if(isPresent) return value;
|
||||||
|
else throw exceptionSupplier.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if(obj == this) return true;
|
||||||
|
if(obj instanceof OptionalFloat) {
|
||||||
|
OptionalFloat other = (OptionalFloat)obj;
|
||||||
|
return (isPresent && other.isPresent ? Float.floatToIntBits(value) == Float.floatToIntBits(other.value) : isPresent == other.isPresent);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return isPresent ? Float.hashCode(value) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return isPresent ? "OptionalFloat["+value+"]" : "OptionalFloat.empty";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
package speiger.src.collections.shorts.functions;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public final class OptionalShort {
|
||||||
|
private static final OptionalShort EMPTY = new OptionalShort();
|
||||||
|
|
||||||
|
private final boolean isPresent;
|
||||||
|
private final short value;
|
||||||
|
|
||||||
|
private OptionalShort() {
|
||||||
|
this.isPresent = false;
|
||||||
|
this.value = (short)0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OptionalShort(short value) {
|
||||||
|
this.isPresent = true;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OptionalShort empty() {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OptionalShort of(short value) {
|
||||||
|
return new OptionalShort(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getAsShort() {
|
||||||
|
if(!isPresent) throw new NoSuchElementException("No value present");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPresent() {
|
||||||
|
return isPresent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return !isPresent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ifPresent(ShortConsumer consumer) {
|
||||||
|
if(isPresent) consumer.accept(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ifPresentOrElse(ShortConsumer action, Runnable emptyAction) {
|
||||||
|
if (isPresent) action.accept(value);
|
||||||
|
else emptyAction.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public short orElse(short other) {
|
||||||
|
return isPresent ? value : other;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short orElseGet(ShortSupplier other) {
|
||||||
|
return isPresent ? value : other.getAsShort();
|
||||||
|
}
|
||||||
|
|
||||||
|
public short orElseThrow() {
|
||||||
|
if (!isPresent) throw new NoSuchElementException("No value present");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <X extends Throwable> short orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
|
||||||
|
if(isPresent) return value;
|
||||||
|
else throw exceptionSupplier.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if(obj == this) return true;
|
||||||
|
if(obj instanceof OptionalShort) {
|
||||||
|
OptionalShort other = (OptionalShort)obj;
|
||||||
|
return (isPresent && other.isPresent ? value == other.value : isPresent == other.isPresent);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return isPresent ? Short.hashCode(value) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return isPresent ? "OptionalShort["+value+"]" : "OptionalShort.empty";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -96,7 +96,7 @@ public abstract class BaseIntIterableTest
|
|||||||
public void testStreamFindFirst() {
|
public void testStreamFindFirst() {
|
||||||
if(getValidIterableTests().contains(IterableTest.STREAM_FIND_FIRST)) {
|
if(getValidIterableTests().contains(IterableTest.STREAM_FIND_FIRST)) {
|
||||||
int expected = IntStream.of(TEST_ARRAY).filter(T -> T / 50 > 0).findFirst().getAsInt();
|
int expected = IntStream.of(TEST_ARRAY).filter(T -> T / 50 > 0).findFirst().getAsInt();
|
||||||
int actual = create(TEST_ARRAY).findFirst(T -> T / 50 > 0);
|
int actual = create(TEST_ARRAY).findFirst(T -> T / 50 > 0).getAsInt();
|
||||||
Assert.assertEquals(expected, actual);
|
Assert.assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user