Skip to content

Commit 18cb299

Browse files
authored
Accept Iterable instead of List in Aggregates.setWindowFields (#963)
1 parent a0aee9a commit 18cb299

File tree

5 files changed

+49
-51
lines changed

5 files changed

+49
-51
lines changed

driver-core/src/main/com/mongodb/client/model/Aggregates.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ public static <TExpression> Bson setWindowFields(@Nullable final TExpression par
648648
* @since 4.3
649649
*/
650650
public static <TExpression> Bson setWindowFields(@Nullable final TExpression partitionBy, @Nullable final Bson sortBy,
651-
final List<WindowedComputation> output) {
651+
final Iterable<? extends WindowedComputation> output) {
652652
notNull("output", output);
653653
return new SetWindowFieldsStage<>(partitionBy, sortBy, output);
654654
}
@@ -1706,9 +1706,12 @@ private static final class SetWindowFieldsStage<TExpression> implements Bson {
17061706
private final TExpression partitionBy;
17071707
@Nullable
17081708
private final Bson sortBy;
1709-
private final List<WindowedComputation> output;
1709+
private final Iterable<? extends WindowedComputation> output;
17101710

1711-
SetWindowFieldsStage(@Nullable final TExpression partitionBy, @Nullable final Bson sortBy, final List<WindowedComputation> output) {
1711+
SetWindowFieldsStage(
1712+
@Nullable final TExpression partitionBy,
1713+
@Nullable final Bson sortBy,
1714+
final Iterable<? extends WindowedComputation> output) {
17121715
this.partitionBy = partitionBy;
17131716
this.sortBy = sortBy;
17141717
this.output = output;

driver-core/src/main/com/mongodb/client/model/Window.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717

1818
import org.bson.conversions.Bson;
1919

20-
import java.util.List;
21-
2220
/**
23-
* A subset of documents within a partition in the {@link Aggregates#setWindowFields(Object, Bson, List) $setWindowFields} pipeline stage
24-
* of an aggregation pipeline (see {@code partitionBy} in {@link Aggregates#setWindowFields(Object, Bson, List)}).
21+
* A subset of documents within a partition in the {@link Aggregates#setWindowFields(Object, Bson, Iterable) $setWindowFields} pipeline stage
22+
* of an aggregation pipeline (see {@code partitionBy} in {@link Aggregates#setWindowFields(Object, Bson, Iterable)}).
2523
*
2624
* @see Windows
2725
* @since 4.3

driver-core/src/main/com/mongodb/client/model/WindowedComputation.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717

1818
import org.bson.conversions.Bson;
1919

20-
import java.util.List;
21-
2220
/**
23-
* The core part of the {@link Aggregates#setWindowFields(Object, Bson, List) $setWindowFields} pipeline stage of an aggregation pipeline.
21+
* The core part of the {@link Aggregates#setWindowFields(Object, Bson, Iterable) $setWindowFields} pipeline stage of an aggregation pipeline.
2422
* A triple of a window function, a {@linkplain Window window} and a path to a field to be computed by the window function over the window.
2523
*
2624
* @see WindowedComputations

driver-core/src/main/com/mongodb/client/model/WindowedComputations.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737

3838
/**
3939
* Builders for {@linkplain WindowedComputation windowed computations} used in the
40-
* {@link Aggregates#setWindowFields(Object, Bson, List) $setWindowFields} pipeline stage
40+
* {@link Aggregates#setWindowFields(Object, Bson, Iterable) $setWindowFields} pipeline stage
4141
* of an aggregation pipeline. Each windowed computation is a triple:
4242
* <ul>
4343
* <li>A window function. Some functions require documents in a window to be sorted
44-
* (see {@code sortBy} in {@link Aggregates#setWindowFields(Object, Bson, List)}).</li>
44+
* (see {@code sortBy} in {@link Aggregates#setWindowFields(Object, Bson, Iterable)}).</li>
4545
* <li>An optional {@linkplain Window window}, a.k.a. frame.
4646
* Specifying {@code null} window is equivalent to specifying an unbounded window,
4747
* i.e., a window with both ends specified as {@link Bound#UNBOUNDED}.
@@ -248,10 +248,10 @@ public static WindowedComputation count(final String path, @Nullable final Windo
248248
/**
249249
* Builds a computation of the time derivative by subtracting the evaluation result of the {@code expression} against the last document
250250
* and the first document in the {@code window} and dividing it by the difference in the values of the
251-
* {@link Aggregates#setWindowFields(Object, Bson, List) sortBy} field of the respective documents.
251+
* {@link Aggregates#setWindowFields(Object, Bson, Iterable) sortBy} field of the respective documents.
252252
* Other documents in the {@code window} have no effect on the computation.
253253
* <p>
254-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) Sorting} is required.</p>
254+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) Sorting} is required.</p>
255255
*
256256
* @param path The output field path.
257257
* @param expression The expression.
@@ -273,10 +273,10 @@ public static <TExpression> WindowedComputation derivative(final String path, fi
273273
/**
274274
* Builds a computation of the time derivative by subtracting the evaluation result of the {@code expression} against the last document
275275
* and the first document in the {@code window} and dividing it by the difference in the BSON {@link BsonType#DATE_TIME Date}
276-
* values of the {@link Aggregates#setWindowFields(Object, Bson, List) sortBy} field of the respective documents.
276+
* values of the {@link Aggregates#setWindowFields(Object, Bson, Iterable) sortBy} field of the respective documents.
277277
* Other documents in the {@code window} have no effect on the computation.
278278
* <p>
279-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) Sorting} is required.</p>
279+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) Sorting} is required.</p>
280280
*
281281
* @param path The output field path.
282282
* @param expression The expression.
@@ -303,13 +303,13 @@ public static <TExpression> WindowedComputation timeDerivative(final String path
303303

304304
/**
305305
* Builds a computation of the approximate integral of a function that maps values of
306-
* the {@link Aggregates#setWindowFields(Object, Bson, List) sortBy} field to evaluation results of the {@code expression}
306+
* the {@link Aggregates#setWindowFields(Object, Bson, Iterable) sortBy} field to evaluation results of the {@code expression}
307307
* against the same document. The limits of integration match the {@code window} bounds.
308308
* The approximation is done by using the
309309
* <a href="https://www.khanacademy.org/math/ap-calculus-ab/ab-integration-new/ab-6-2/a/understanding-the-trapezoid-rule">
310310
* trapezoidal rule</a>.
311311
* <p>
312-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) Sorting} is required.</p>
312+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) Sorting} is required.</p>
313313
*
314314
* @param path The output field path.
315315
* @param expression The expression.
@@ -329,11 +329,11 @@ public static <TExpression> WindowedComputation integral(final String path, fina
329329

330330
/**
331331
* Builds a computation of the approximate integral of a function that maps BSON {@link BsonType#DATE_TIME Date} values of
332-
* the {@link Aggregates#setWindowFields(Object, Bson, List) sortBy} field to evaluation results of the {@code expression}
332+
* the {@link Aggregates#setWindowFields(Object, Bson, Iterable) sortBy} field to evaluation results of the {@code expression}
333333
* against the same document. The limits of integration match the {@code window} bounds.
334334
* The approximation is done by using the trapezoidal rule.
335335
* <p>
336-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) Sorting} is required.</p>
336+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) Sorting} is required.</p>
337337
*
338338
* @param path The output field path.
339339
* @param expression The expression.
@@ -408,7 +408,7 @@ public static <TExpression> WindowedComputation covariancePop(final String path,
408408
* that includes {@code n} - 1 documents preceding the current document and the current document, with more weight on documents
409409
* closer to the current one.
410410
* <p>
411-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) Sorting} is required.</p>
411+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) Sorting} is required.</p>
412412
*
413413
* @param path The output field path.
414414
* @param expression The expression.
@@ -431,7 +431,7 @@ public static <TExpression> WindowedComputation expMovingAvg(final String path,
431431
* Builds a computation of the exponential moving average of the evaluation results of the {@code expression} over the half-bounded
432432
* window [{@link Bound#UNBOUNDED}, {@link Bound#CURRENT}], with {@code alpha} representing the degree of weighting decrease.
433433
* <p>
434-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) Sorting} is required.</p>
434+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) Sorting} is required.</p>
435435
*
436436
* @param path The output field path.
437437
* @param expression The expression.
@@ -455,7 +455,7 @@ public static <TExpression> WindowedComputation expMovingAvg(final String path,
455455
/**
456456
* Builds a computation that adds the evaluation results of the {@code expression} over the {@code window}
457457
* to a BSON {@link org.bson.BsonType#ARRAY Array}.
458-
* Order within the array is guaranteed if {@link Aggregates#setWindowFields(Object, Bson, List) sortBy} is specified.
458+
* Order within the array is guaranteed if {@link Aggregates#setWindowFields(Object, Bson, Iterable) sortBy} is specified.
459459
*
460460
* @param path The output field path.
461461
* @param expression The expression.
@@ -492,7 +492,7 @@ public static <TExpression> WindowedComputation addToSet(final String path, fina
492492
/**
493493
* Builds a computation of the evaluation result of the {@code expression} against the first document in the {@code window}.
494494
* <p>
495-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) Sorting} is required.</p>
495+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) Sorting} is required.</p>
496496
*
497497
* @param path The output field path.
498498
* @param expression The expression.
@@ -512,7 +512,7 @@ public static <TExpression> WindowedComputation first(final String path, final T
512512
* of evaluation results of the {@code inExpression} against the first {@code N} documents in the {@code window},
513513
* where {@code N} is the positive integral value of the {@code nExpression}.
514514
* <p>
515-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) Sorting} is required.</p>
515+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) Sorting} is required.</p>
516516
*
517517
* @param path The output field path.
518518
* @param inExpression The input expression.
@@ -595,7 +595,7 @@ public static <OutExpression, NExpression> WindowedComputation topN(
595595
/**
596596
* Builds a computation of the evaluation result of the {@code expression} against the last document in the {@code window}.
597597
* <p>
598-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) Sorting} is required.</p>
598+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) Sorting} is required.</p>
599599
*
600600
* @param path The output field path.
601601
* @param expression The expression.
@@ -615,7 +615,7 @@ public static <TExpression> WindowedComputation last(final String path, final TE
615615
* of evaluation results of the {@code inExpression} against the last {@code N} documents in the {@code window},
616616
* where {@code N} is the positive integral value of the {@code nExpression}.
617617
* <p>
618-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) Sorting} is required.</p>
618+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) Sorting} is required.</p>
619619
*
620620
* @param path The output field path.
621621
* @param inExpression The input expression.
@@ -698,10 +698,10 @@ public static <OutExpression, NExpression> WindowedComputation bottomN(
698698
/**
699699
* Builds a computation of the evaluation result of the {@code expression} for the document whose position is shifted by the given
700700
* amount relative to the current document. If the shifted document is outside of the
701-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) partition} containing the current document,
701+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) partition} containing the current document,
702702
* then the {@code defaultExpression} is used instead of the {@code expression}.
703703
* <p>
704-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) Sorting} is required.</p>
704+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) Sorting} is required.</p>
705705
*
706706
* @param path The output field path.
707707
* @param expression The expression.
@@ -733,9 +733,9 @@ public static <TExpression> WindowedComputation shift(final String path, final T
733733

734734
/**
735735
* Builds a computation of the order number of each document in its
736-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) partition}.
736+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) partition}.
737737
* <p>
738-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) Sorting} is required.</p>
738+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) Sorting} is required.</p>
739739
*
740740
* @param path The output field path.
741741
* @return The constructed windowed computation.
@@ -748,13 +748,13 @@ public static WindowedComputation documentNumber(final String path) {
748748

749749
/**
750750
* Builds a computation of the rank of each document in its
751-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) partition}.
752-
* Documents with the same value(s) of the {@linkplain Aggregates#setWindowFields(Object, Bson, List) sortBy} fields result in
751+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) partition}.
752+
* Documents with the same value(s) of the {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) sortBy} fields result in
753753
* the same ranking and result in gaps in the returned ranks.
754754
* For example, a partition with the sequence [1, 3, 3, 5] representing the values of the single {@code sortBy} field
755755
* produces the following sequence of rank values: [1, 2, 2, 4].
756756
* <p>
757-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) Sorting} is required.</p>
757+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) Sorting} is required.</p>
758758
*
759759
* @param path The output field path.
760760
* @return The constructed windowed computation.
@@ -767,13 +767,13 @@ public static WindowedComputation rank(final String path) {
767767

768768
/**
769769
* Builds a computation of the dense rank of each document in its
770-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) partition}.
771-
* Documents with the same value(s) of the {@linkplain Aggregates#setWindowFields(Object, Bson, List) sortBy} fields result in
770+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) partition}.
771+
* Documents with the same value(s) of the {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) sortBy} fields result in
772772
* the same ranking but do not result in gaps in the returned ranks.
773773
* For example, a partition with the sequence [1, 3, 3, 5] representing the values of the single {@code sortBy} field
774774
* produces the following sequence of rank values: [1, 2, 2, 3].
775775
* <p>
776-
* {@linkplain Aggregates#setWindowFields(Object, Bson, List) Sorting} is required.</p>
776+
* {@linkplain Aggregates#setWindowFields(Object, Bson, Iterable) Sorting} is required.</p>
777777
*
778778
* @param path The output field path.
779779
* @return The constructed windowed computation.

0 commit comments

Comments
 (0)