Ranides Atterwim 4 yıl önce
ebeveyn
işleme
6411e6ba91

+ 21 - 0
assira.core/src/main/java/net/ranides/assira/collection/query/derived/CQAppend.java

@@ -12,18 +12,39 @@ import java.util.function.Consumer;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
 
+/**
+ * Composite query, collecting many queries inside.
+ * It reports "feature" if all queries support it.
+ * Used by {@link CQuery#append(CQuery)} operation.
+ *
+ * @param <T> T
+ */
 public class CQAppend<T> extends CQueryAbstract<T> {
 
     private final CQuery<T>[] array;
 
     private int flags;
 
+    /**
+     * Merges two queries into one composite.
+     * It is public starting point used by clients.
+     *
+     * @param a a
+     * @param b b
+     */
     @SuppressWarnings("unchecked")
     public CQAppend(CQuery<T> a, CQuery<T> b) {
         this.array = new CQuery[]{a, b};
         this.flags = BaseFeatures.and(a, b);
     }
 
+    /**
+     * Merges two queries into one composite.
+     * It is private starting point used by CQAppend to optimize CQAppend grow.
+     *
+     * @param a a
+     * @param b b
+     */
     public CQAppend(CQAppend<T> a, CQuery<T> b) {
         this.array = ArrayUtils.append(a.array, b);
         this.flags = BaseFeatures.and(a, b);

+ 25 - 0
assira.core/src/main/java/net/ranides/assira/collection/query/derived/CQFilter.java

@@ -9,14 +9,39 @@ import java.util.function.Predicate;
 import java.util.function.Supplier;
 import java.util.stream.Stream;
 
+/**
+ * Adapter query: it filters provided stream using predicate.
+ * Used by {@link CQuery#filter(Predicate)} operation.
+ *
+ * Supports fast iterator and stream if source supports it.
+ * Does not support other fast operations.
+ *
+ * It supports statefull predicates which can be used for example, by "distinct" operation.
+ *
+ * @param <T> T
+ */
 public class CQFilter<T> extends CQAbstractFilter<T,T> {
     private final Supplier<Predicate<? super T>> p;
 
+    /**
+     * Creates new filtered query.
+     * It assumes that predicate is stateless, and is reused by all terminal operations.
+     *
+     * @param source source
+     * @param predicate predicate
+     */
     public CQFilter(CQuery<T> source, Predicate<? super T> predicate) {
         super(source);
         this.p = () -> predicate;
     }
 
+    /**
+     * Creates new filtered query.
+     * It assummes that supplier creates statefull predicate, which is recreated by every terminal operation.
+     *
+     * @param source source
+     * @param predicate predicate
+     */
     public CQFilter(CQuery<T> source, Supplier<Predicate<? super T>> predicate) {
         super(source);
         this.p = predicate;

+ 20 - 2
assira.core/src/main/java/net/ranides/assira/collection/query/derived/CQFilterEach.java

@@ -10,13 +10,31 @@ import java.util.Iterator;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
 
+/**
+ * Adapter query: it filters provided stream using predicate.
+ * Use by {@link CQuery#filterEach(EachPredicate)} operation.
+ *
+ * Supports fast iterator and stream if source supports it.
+ * Does not support other fast operations.
+ *
+ * It supports stateless predicates only
+ *
+ * @param <T> T
+ */
 public class CQFilterEach<T> extends CQAbstractFilter<T, T> {
 
     private final Predicates.EachPredicate<? super T> p;
 
-    public CQFilterEach(CQuery<T> source, Predicates.EachPredicate<? super T> p) {
+    /**
+     * Creates new filtered query.
+     * It assumes that predicate is stateless, and is reused by all terminal operations.
+     *
+     * @param source source
+     * @param predicate predicate
+     */
+    public CQFilterEach(CQuery<T> source, Predicates.EachPredicate<? super T> predicate) {
         super(source);
-        this.p = p;
+        this.p = predicate;
     }
 
     @Override

+ 19 - 0
assira.core/src/main/java/net/ranides/assira/collection/query/derived/CQLimit.java

@@ -9,10 +9,29 @@ import java.util.Iterator;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
 
+/**
+ * Adapter query: it filters provided stream using predicate.
+ * Stops instantly when predicate returns "false"
+ * Use by {@link CQuery#limit(Predicate)} operation.
+ *
+ * Supports fast iterator and stream if source supports it.
+ * Does not support other fast operations.
+ *
+ * It supports stateless predicates only
+ *
+ * @param <T> T
+ */
 public class CQLimit<T> extends CQAbstractFilter<T, T> {
 
     private final Predicate<? super T> p;
 
+    /**
+     * Creates new filtered query.
+     * It assumes that predicate is stateless, and is reused by all terminal operations.
+     *
+     * @param source source
+     * @param p predicate
+     */
     public CQLimit(CQuery<T> source, Predicate<? super T> p) {
         super(source);
         this.p = p;

+ 11 - 0
assira.core/src/main/java/net/ranides/assira/collection/query/derived/CQMap.java

@@ -16,6 +16,17 @@ import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
 
+/**
+ * Adapter query: it calculates new value for every item.
+ * Used by {@link CQuery#map(Function)} operation.
+ *
+ * It supports stateless mappings only.
+ *
+ * Supports all features supported by source query, except "list".
+ *
+ * @param <S> S
+ * @param <T> T
+ */
 @RequiredArgsConstructor
 public class CQMap<S,T> extends CQueryAbstract<T> {
 

+ 12 - 0
assira.core/src/main/java/net/ranides/assira/collection/query/derived/CQMapEach.java

@@ -13,10 +13,22 @@ import net.ranides.assira.functional.Predicates;
 import java.util.Iterator;
 import java.util.List;
 import java.util.function.Consumer;
+import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 
+/**
+ * Adapter query: it calculates new value for every item.
+ * Used by {@link CQuery#map(Function)} operation.
+ *
+ * It supports stateless mappings only.
+ *
+ * Supports all features supported by source query, except "list".
+ *
+ * @param <S> S
+ * @param <T> T
+ */
 @RequiredArgsConstructor
 public class CQMapEach<S,T> extends CQueryAbstract<T> {
 

+ 19 - 0
assira.core/src/main/java/net/ranides/assira/collection/query/derived/CQMapOptional.java

@@ -10,10 +10,29 @@ import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
 
+/**
+ * Adapter query: it calculates new value for every item or skips it.
+ * Its behaviour is more like "CQFilter" than "CQMap"
+ * Used by {@link CQuery#mapOptional(Function)} (Function)} operation.
+ *
+ * It supports stateless mappings only.
+ *
+ * Supports fast iterator and stream if source supports it.
+ * Does not support other fast operations.
+ *
+ * @param <T> T
+ * @param <R> R
+ */
 public class CQMapOptional<T, R> extends CQAbstractFilter<T, R> {
 
     private final Function<? super T, Optional<R>> f;
 
+    /**
+     * Creates new query with values computed by provided function
+     *
+     * @param source source
+     * @param f f
+     */
     public CQMapOptional(CQuery<T> source, Function<? super T, Optional<R>> f) {
         super(source);
         this.f = f;

+ 13 - 0
assira.core/src/main/java/net/ranides/assira/collection/query/derived/CQPrefetch.java

@@ -6,10 +6,23 @@ import net.ranides.assira.generic.LazyReference;
 
 import java.util.function.Supplier;
 
+/**
+ * Adapter query: it fetches collected data on demand.
+ * Used by {@link CQuery#prefetch()} operation.
+ *
+ * Because it uses "fetch" operation, it supports all fast features.
+ *
+ * @param <T> T
+ */
 public class CQPrefetch<T> extends CQQuerySupplier<T> {
 
     private final Supplier<CQuery<T>> source;
 
+    /**
+     * Creates new prefetched query.
+     *
+     * @param source source
+     */
     public CQPrefetch(CQuery<T> source) {
         this.source = LazyReference.shared(() -> source.fetch());
     }

+ 9 - 0
assira.core/src/main/java/net/ranides/assira/collection/query/derived/CQReverse.java

@@ -8,6 +8,15 @@ import net.ranides.assira.collection.query.base.CQListSupplier;
 
 import java.util.List;
 
+/**
+ * Adapter query: it converts source query into list and reverses order.
+ * Used by {@link CQuery#reverse()} operation.
+ *
+ * It supports all fast features, if source supports fast "list".
+ * It does not support any fast features in other case.
+ *
+ * @param <T> T
+ */
 @RequiredArgsConstructor
 public class CQReverse<T> extends CQListSupplier<T> {
     private final CQuery<T> that;

+ 26 - 1
assira.core/src/main/java/net/ranides/assira/collection/query/derived/CQSlice.java

@@ -8,8 +8,18 @@ import net.ranides.assira.functional.Predicates;
 import net.ranides.assira.math.MathUtils;
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.stream.Stream;
 
+/**
+ * Adapter query: it returns only specified fragment of source query.
+ * Used by {@link CQuery#slice(int, int)} operation.
+ *
+ * It reports all features supported by source except "each".
+ * Fast "each" is reported only, if selected slice does not skip more elements than "FAST_SKIP_LIMIT"
+ *
+ * @param <T> T
+ */
 public class CQSlice<T> extends CQueryAbstract<T> {
 
     private static final int FAST_SKIP_LIMIT = 1;
@@ -18,6 +28,13 @@ public class CQSlice<T> extends CQueryAbstract<T> {
     private final int begin;
     private final int end;
 
+    /**
+     * Creates new slice with provided range.
+     *
+     * @param source source
+     * @param begin begin
+     * @param end end
+     */
     public CQSlice(CQuery<T> source, int begin, int end) {
         this.source = source;
         this.begin = Math.max(0, begin);
@@ -46,7 +63,7 @@ public class CQSlice<T> extends CQueryAbstract<T> {
 
     @Override
     public boolean hasFastList() {
-        return false;
+        return source.features().hasFastList();
     }
 
     @Override
@@ -74,6 +91,14 @@ public class CQSlice<T> extends CQueryAbstract<T> {
         return source.stream().skip(begin).limit(end-begin);
     }
 
+    @Override
+    public List<T> list() {
+        if(hasFastList()) {
+            return source.list().subList(begin, Math.min(source.size(), end));
+        }
+        return super.list();
+    }
+
     @Override
     public int size() {
         return Math.max(0, Math.min(source.size(), end) - begin);

+ 9 - 0
assira.core/src/main/java/net/ranides/assira/collection/query/derived/CQSort.java

@@ -11,6 +11,15 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.stream.Stream;
 
+/**
+ * Adapter query: it sorts elements from source every time, when terminal operation is called.
+ * It is used by {@link CQuery#sort()}.
+ *
+ * It does not support any fast operations except "length".
+ * Reports fast length if source stream reports it.
+ *
+ * @param <T> T
+ */
 @RequiredArgsConstructor
 public class CQSort<T> extends CQListSupplier<T> {
 

+ 0 - 1
assira.core/src/main/java/net/ranides/assira/collection/query/support/BaseListParalell.java

@@ -45,7 +45,6 @@ public class BaseListParalell {
                 return null;
             });
         }
-        System.out.println(">>>>> LIST: " + tasks.size());
         ForkJoinPool.commonPool().invokeAll(tasks);
     }