|
|
@@ -4,6 +4,7 @@ import lombok.experimental.UtilityClass;
|
|
|
|
|
|
import net.ranides.assira.collection.query.CQuery;
|
|
|
import net.ranides.assira.functional.Predicates;
|
|
|
+import net.ranides.assira.functional.Predicates.EachPredicate;
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
@@ -78,15 +79,15 @@ public class BaseStream {
|
|
|
return that.stream().allMatch(v -> consumer.test(v));
|
|
|
}
|
|
|
|
|
|
- public static <T> boolean whileEach(CQuery<T> that, Predicates.EachPredicate<? super T> consumer) {
|
|
|
+ public static <T> boolean whileEach(CQuery<T> that, EachPredicate<? super T> consumer) {
|
|
|
BaseState.Index index = BaseState.newIndex(that);
|
|
|
return that.stream().allMatch(v -> consumer.test(index.next(), v));
|
|
|
}
|
|
|
|
|
|
- public static <T> int indexOf(CQuery<T> that, Predicate<? super T> predicate) {
|
|
|
+ public static <T> int indexOf(CQuery<T> that, EachPredicate<? super T> predicate) {
|
|
|
BaseState.Holder<Integer> out = BaseState.newHolder(that, -1);
|
|
|
whileEach(that, (i,v) -> {
|
|
|
- if(predicate.test(v)) {
|
|
|
+ if(predicate.test(i,v)) {
|
|
|
out.set(i);
|
|
|
return false;
|
|
|
}
|
|
|
@@ -95,12 +96,13 @@ public class BaseStream {
|
|
|
return out.get();
|
|
|
}
|
|
|
|
|
|
- public static <T> int lastIndexOf(CQuery<T> that, Predicate<? super T> predicate) {
|
|
|
+ public static <T> int lastIndexOf(CQuery<T> that, EachPredicate<? super T> predicate) {
|
|
|
BaseState.Holder<Integer> out = BaseState.newHolder(that, -1);
|
|
|
BaseState.Index index = BaseState.newIndex(that);
|
|
|
that.stream().forEach(v -> {
|
|
|
- if(predicate.test(v)) {
|
|
|
- out.set(index.value());
|
|
|
+ int let_index = index.value();
|
|
|
+ if(predicate.test(let_index,v)) {
|
|
|
+ out.set(let_index);
|
|
|
}
|
|
|
index.next();
|
|
|
});
|