|
|
@@ -54,7 +54,6 @@ public interface CQuery<T> extends Iterable<T> {
|
|
|
|
|
|
/**
|
|
|
* Returns BUILDER which allows construction Query by wrapping provided data source (for example: in memory collection).
|
|
|
- * This is facade method: it allows creation from single data source.
|
|
|
*
|
|
|
* @param <T> T
|
|
|
* @return builder
|
|
|
@@ -64,18 +63,6 @@ public interface CQuery<T> extends Iterable<T> {
|
|
|
return WrapBuilder.INSTANCE;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Returns new Query which compute results by creating new Stream in every terminate method.
|
|
|
- * Supplier can create different stream on every call.|
|
|
|
- *
|
|
|
- * @param source source
|
|
|
- * @param <T> T
|
|
|
- * @return query
|
|
|
- */
|
|
|
- static <T> CQuery<T> from(CheckedSupplier<Stream<T>,?> source) {
|
|
|
- return from().stream(source);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Returns new Query which compute results by using provided collection.
|
|
|
* Collection can be modified between call.
|
|
|
@@ -1484,6 +1471,65 @@ public interface CQuery<T> extends Iterable<T> {
|
|
|
return iterable(() -> IteratorUtils.infinite(identity, source));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Creates query with finite number of elements. Each item is created by subsequent calls to generator.
|
|
|
+ *
|
|
|
+ * Please note, that means generator should be statefull.
|
|
|
+ * Please note, that it is impossible to "rewind" generator, which means generated infinite stream probably
|
|
|
+ * will return different results on every call.
|
|
|
+ *
|
|
|
+ * @param source source
|
|
|
+ * @param <T> T
|
|
|
+ * @return query
|
|
|
+ */
|
|
|
+ public final <T extends F> CQuery<T> finite(CheckedSupplier<Optional<T>, ?> source) {
|
|
|
+ return iterable(() -> IteratorUtils.finite(source));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates query with finite number of elements. Each item is created by subsequent calls to generator.
|
|
|
+ *
|
|
|
+ * Please note, that generator does not need to be statefull.
|
|
|
+ * Generates receives "previously" computed result (or identity at start) and can make computation using it.
|
|
|
+ * For example, it can create all natural numbers by simple incrementation.
|
|
|
+ *
|
|
|
+ * @param identity starting value passed to generator
|
|
|
+ * @param source source
|
|
|
+ * @param <T> T
|
|
|
+ * @return query
|
|
|
+ */
|
|
|
+ public final <T extends F> CQuery<T> finite(T identity, CheckedFunction<T, Optional<T>, ?> source) {
|
|
|
+ return iterable(() -> IteratorUtils.finite(identity, source));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates query with virtual list made of generated elements
|
|
|
+ * Element as each index is computed by "function" at every access.
|
|
|
+ * Size of the list provided as first argument
|
|
|
+ *
|
|
|
+ * @param size size
|
|
|
+ * @param function function
|
|
|
+ * @param <T> T
|
|
|
+ * @return query
|
|
|
+ */
|
|
|
+ public final <T extends F> CQuery<T> finite(int size, IntFunction<? extends T> function) {
|
|
|
+ return CQuery.from().list(VirtualList.of(size, function));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates query with virtual list made of generated elements
|
|
|
+ * Element as each index is computed by "function" at every access.
|
|
|
+ * Size of the list computed by supplier provided as first argument.
|
|
|
+ *
|
|
|
+ * @param size size
|
|
|
+ * @param function function
|
|
|
+ * @param <T> T
|
|
|
+ * @return query
|
|
|
+ */
|
|
|
+ public final <T extends F> CQuery<T> finite(IntSupplier size, IntFunction<? extends T> function) {
|
|
|
+ return CQuery.from().list(VirtualList.of(size, function));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Creates stream with natural numbers from specified range.
|
|
|
*
|