@@ -216,6 +216,27 @@ public Floor floor() {
216
216
return usesFieldRef () ? Floor .floorValueOf (fieldReference ) : Floor .floorValueOf (expression );
217
217
}
218
218
219
+ /**
220
+ * Creates new {@link AggregationExpression} that calculates the approximation for the mathematical integral value.
221
+ *
222
+ * @return new instance of {@link Integral}.
223
+ * @since 3.3
224
+ */
225
+ public Integral integral () {
226
+ return usesFieldRef () ? Integral .integralOf (fieldReference ) : Integral .integralOf (expression );
227
+ }
228
+
229
+ /**
230
+ * Creates new {@link AggregationExpression} that calculates the approximation for the mathematical integral value.
231
+ *
232
+ * @param unit the unit of measure.
233
+ * @return new instance of {@link Integral}.
234
+ * @since 3.3
235
+ */
236
+ public Integral integral (String unit ) {
237
+ return integral ().unit (unit );
238
+ }
239
+
219
240
/**
220
241
* Creates new {@link AggregationExpression} that calculates the natural logarithm ln (i.e loge) of the assoicated
221
242
* number.
@@ -520,8 +541,8 @@ public StdDevSamp stdDevSamp() {
520
541
}
521
542
522
543
/**
523
- * Creates new {@link AggregationExpression} that uses the previous input (field/expression) and the value of the given
524
- * field to calculate the population covariance of the two.
544
+ * Creates new {@link AggregationExpression} that uses the previous input (field/expression) and the value of the
545
+ * given field to calculate the population covariance of the two.
525
546
*
526
547
* @param fieldReference must not be {@literal null}.
527
548
* @return new instance of {@link CovariancePop}.
@@ -532,8 +553,8 @@ public CovariancePop covariancePop(String fieldReference) {
532
553
}
533
554
534
555
/**
535
- * Creates new {@link AggregationExpression} that uses the previous input (field/expression) and the result of the given
536
- * {@link AggregationExpression expression} to calculate the population covariance of the two.
556
+ * Creates new {@link AggregationExpression} that uses the previous input (field/expression) and the result of the
557
+ * given {@link AggregationExpression expression} to calculate the population covariance of the two.
537
558
*
538
559
* @param expression must not be {@literal null}.
539
560
* @return new instance of {@link CovariancePop}.
@@ -548,8 +569,8 @@ private CovariancePop covariancePop() {
548
569
}
549
570
550
571
/**
551
- * Creates new {@link AggregationExpression} that uses the previous input (field/expression) and the value of the given
552
- * field to calculate the sample covariance of the two.
572
+ * Creates new {@link AggregationExpression} that uses the previous input (field/expression) and the value of the
573
+ * given field to calculate the sample covariance of the two.
553
574
*
554
575
* @param fieldReference must not be {@literal null}.
555
576
* @return new instance of {@link CovariancePop}.
@@ -560,8 +581,8 @@ public CovarianceSamp covarianceSamp(String fieldReference) {
560
581
}
561
582
562
583
/**
563
- * Creates new {@link AggregationExpression} that uses the previous input (field/expression) and the result of the given
564
- * {@link AggregationExpression expression} to calculate the sample covariance of the two.
584
+ * Creates new {@link AggregationExpression} that uses the previous input (field/expression) and the result of the
585
+ * given {@link AggregationExpression expression} to calculate the sample covariance of the two.
565
586
*
566
587
* @param expression must not be {@literal null}.
567
588
* @return new instance of {@link CovariancePop}.
@@ -1798,4 +1819,54 @@ protected String getMongoMethod() {
1798
1819
return "$derivative" ;
1799
1820
}
1800
1821
}
1822
+
1823
+ /**
1824
+ * Value object to represent an {@link AggregationExpression expression} that calculates the approximation for the
1825
+ * mathematical integral value.
1826
+ *
1827
+ * @author Christoph Strobl
1828
+ * @since 3.3
1829
+ */
1830
+ public static class Integral extends AbstractAggregationExpression {
1831
+
1832
+ private Integral (Object value ) {
1833
+ super (value );
1834
+ }
1835
+
1836
+ /**
1837
+ * Create a new instance of {@link Integral} for the value stored at the given field holding a numeric value.
1838
+ *
1839
+ * @param fieldReference must not be {@literal null}.
1840
+ * @return new instance of {@link Integral}.
1841
+ */
1842
+ public static Integral integralOf (String fieldReference ) {
1843
+ return new Integral (Collections .singletonMap ("input" , Fields .field (fieldReference )));
1844
+ }
1845
+
1846
+ /**
1847
+ * Create a new instance of {@link Integral} for the value provided by the given expression that resolves to a
1848
+ * numeric value.
1849
+ *
1850
+ * @param expression must not be {@literal null}.
1851
+ * @return new instance of {@link Integral}.
1852
+ */
1853
+ public static Integral integralOf (AggregationExpression expression ) {
1854
+ return new Integral (Collections .singletonMap ("input" , expression ));
1855
+ }
1856
+
1857
+ /**
1858
+ * Set the unit of measure.
1859
+ *
1860
+ * @param unit the unit of measure.
1861
+ * @return new instance of {@link Integral}.
1862
+ */
1863
+ public Integral unit (String unit ) {
1864
+ return new Integral (append ("unit" , unit ));
1865
+ }
1866
+
1867
+ @ Override
1868
+ protected String getMongoMethod () {
1869
+ return "$integral" ;
1870
+ }
1871
+ }
1801
1872
}
0 commit comments