|
@@ -6,16 +6,6 @@
|
|
|
*/
|
|
*/
|
|
|
package net.ranides.assira.collection.query;
|
|
package net.ranides.assira.collection.query;
|
|
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
-import java.nio.file.Files;
|
|
|
|
|
-import java.nio.file.Path;
|
|
|
|
|
-import java.util.*;
|
|
|
|
|
-import java.util.function.*;
|
|
|
|
|
-import java.util.stream.Collector;
|
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
-import java.util.stream.Stream;
|
|
|
|
|
-import java.util.stream.StreamSupport;
|
|
|
|
|
-
|
|
|
|
|
import net.ranides.assira.collection.HashFunction;
|
|
import net.ranides.assira.collection.HashFunction;
|
|
|
import net.ranides.assira.collection.arrays.ArrayUtils;
|
|
import net.ranides.assira.collection.arrays.ArrayUtils;
|
|
|
import net.ranides.assira.collection.iterators.IteratorUtils;
|
|
import net.ranides.assira.collection.iterators.IteratorUtils;
|
|
@@ -25,13 +15,25 @@ import net.ranides.assira.collection.sets.CustomSet;
|
|
|
import net.ranides.assira.collection.sets.HashSet;
|
|
import net.ranides.assira.collection.sets.HashSet;
|
|
|
import net.ranides.assira.collection.sets.RBTreeSet;
|
|
import net.ranides.assira.collection.sets.RBTreeSet;
|
|
|
import net.ranides.assira.functional.Consumers.EachConsumer;
|
|
import net.ranides.assira.functional.Consumers.EachConsumer;
|
|
|
|
|
+import net.ranides.assira.functional.FunctionUtils;
|
|
|
import net.ranides.assira.functional.Functions.EachFunction;
|
|
import net.ranides.assira.functional.Functions.EachFunction;
|
|
|
import net.ranides.assira.functional.Predicates.EachPredicate;
|
|
import net.ranides.assira.functional.Predicates.EachPredicate;
|
|
|
import net.ranides.assira.functional.special.Fold;
|
|
import net.ranides.assira.functional.special.Fold;
|
|
|
import net.ranides.assira.generic.CompareUtils;
|
|
import net.ranides.assira.generic.CompareUtils;
|
|
|
|
|
+import net.ranides.assira.generic.LazyReference;
|
|
|
import net.ranides.assira.generic.SerializationUtils;
|
|
import net.ranides.assira.generic.SerializationUtils;
|
|
|
import net.ranides.assira.generic.TypeToken;
|
|
import net.ranides.assira.generic.TypeToken;
|
|
|
-import net.ranides.assira.reflection.*;
|
|
|
|
|
|
|
+import net.ranides.assira.reflection.IClass;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
|
+import java.nio.file.Path;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.function.*;
|
|
|
|
|
+import java.util.stream.Collector;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
+import java.util.stream.StreamSupport;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
@@ -74,6 +76,11 @@ public abstract class CQueryAbstract<T> implements CQuery<T> {
|
|
|
return CQuery.from().collection(list());
|
|
return CQuery.from().collection(list());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CQuery<T> prefetch() {
|
|
|
|
|
+ return new CQPrefetch<>(this);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public CQuery<T> cache(Path filename) throws IOException {
|
|
public CQuery<T> cache(Path filename) throws IOException {
|
|
|
List<T> data;
|
|
List<T> data;
|
|
@@ -147,7 +154,7 @@ public abstract class CQueryAbstract<T> implements CQuery<T> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public <R> CQuery<R> mapOptional(Function<? super T, Optional<? extends R>> f) {
|
|
|
|
|
|
|
+ public <R> CQuery<R> mapOptional(Function<? super T, Optional<R>> f) {
|
|
|
return map(f).filter(Optional::isPresent).map(Optional::get);
|
|
return map(f).filter(Optional::isPresent).map(Optional::get);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -293,24 +300,31 @@ public abstract class CQueryAbstract<T> implements CQuery<T> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public final CQuery<T> each(Consumer<? super T> consumer) {
|
|
|
|
|
|
|
+ public final void each(Consumer<? super T> consumer) {
|
|
|
stream().forEach(consumer);
|
|
stream().forEach(consumer);
|
|
|
- return this;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public final CQuery<T> each(EachConsumer<? super T> consumer) {
|
|
|
|
|
|
|
+ public final void each(EachConsumer<? super T> consumer) {
|
|
|
int index = 0;
|
|
int index = 0;
|
|
|
for (T t : this) {
|
|
for (T t : this) {
|
|
|
consumer.apply(index++, t);
|
|
consumer.apply(index++, t);
|
|
|
}
|
|
}
|
|
|
- return this;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public CQuery<T> into(Collection<? super T> collection) {
|
|
|
|
|
|
|
+ public final CQuery<T> onEach(Consumer<? super T> consumer) {
|
|
|
|
|
+ return map(FunctionUtils.asFunction(consumer));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public final CQuery<T> onEach(EachConsumer<? super T> consumer) {
|
|
|
|
|
+ return mapEach(FunctionUtils.asEachFunction(consumer));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void into(Collection<? super T> collection) {
|
|
|
stream().forEach(collection::add);
|
|
stream().forEach(collection::add);
|
|
|
- return this;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -606,6 +620,30 @@ public abstract class CQueryAbstract<T> implements CQuery<T> {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ protected static class CQPrefetch<T> extends CQueryAbstract<T> {
|
|
|
|
|
+
|
|
|
|
|
+ private final Supplier<CQuery<T>> source;
|
|
|
|
|
+
|
|
|
|
|
+ public CQPrefetch(CQuery<T> source) {
|
|
|
|
|
+ this.source = LazyReference.shared(() -> source.fetch());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Stream<T> stream() {
|
|
|
|
|
+ return source.get().stream();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Iterator<T> iterator() {
|
|
|
|
|
+ return source.get().iterator();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int size() {
|
|
|
|
|
+ return source.get().size();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
protected static class CQSingle<T> extends CQueryAbstract<T> {
|
|
protected static class CQSingle<T> extends CQueryAbstract<T> {
|
|
|
|
|
|
|
|
private final T value;
|
|
private final T value;
|