|
@@ -14,6 +14,8 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.function.BiConsumer;
|
|
import java.util.function.BiConsumer;
|
|
|
import java.util.function.BinaryOperator;
|
|
import java.util.function.BinaryOperator;
|
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
@@ -26,18 +28,18 @@ import java.util.stream.Collector;
|
|
|
public class BaseEach {
|
|
public class BaseEach {
|
|
|
|
|
|
|
|
public static <T> int size(CQuery<T> that) {
|
|
public static <T> int size(CQuery<T> that) {
|
|
|
- int[] out = {0};
|
|
|
|
|
- that.forEach(v -> out[0]++);
|
|
|
|
|
- return out[0];
|
|
|
|
|
|
|
+ AtomicInteger index = new AtomicInteger(0);
|
|
|
|
|
+ that.forEach(v -> index.getAndIncrement());
|
|
|
|
|
+ return index.get();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static <T> boolean isEmpty(CQuery<T> that) {
|
|
public static <T> boolean isEmpty(CQuery<T> that) {
|
|
|
- boolean[] out = {true};
|
|
|
|
|
|
|
+ AtomicBoolean out = new AtomicBoolean(true);
|
|
|
that.whileEach(v -> {
|
|
that.whileEach(v -> {
|
|
|
- out[0] = false;
|
|
|
|
|
|
|
+ out.set(false);
|
|
|
return false;
|
|
return false;
|
|
|
});
|
|
});
|
|
|
- return out[0];
|
|
|
|
|
|
|
+ return out.get();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static <T, A, R> R collect(CQuery<T> that, Collector<? super T, A, R> collector) {
|
|
public static <T, A, R> R collect(CQuery<T> that, Collector<? super T, A, R> collector) {
|