@@ -142,6 +142,63 @@ public StdDevSamp stdDevSamp() {
142
142
return usesFieldRef () ? StdDevSamp .stdDevSampOf (fieldReference ) : StdDevSamp .stdDevSampOf (expression );
143
143
}
144
144
145
+ /**
146
+ * Creates new {@link AggregationExpression} that uses the previous input (field/expression) and the value of the given
147
+ * field to calculate the population covariance of the two.
148
+ *
149
+ * @param fieldReference must not be {@literal null}.
150
+ * @return new instance of {@link CovariancePop}.
151
+ * @since 3.3
152
+ */
153
+ public CovariancePop covariancePop (String fieldReference ) {
154
+ return covariancePop ().and (fieldReference );
155
+ }
156
+
157
+ /**
158
+ * Creates new {@link AggregationExpression} that uses the previous input (field/expression) and the result of the given
159
+ * {@link AggregationExpression expression} to calculate the population covariance of the two.
160
+ *
161
+ * @param expression must not be {@literal null}.
162
+ * @return new instance of {@link CovariancePop}.
163
+ * @since 3.3
164
+ */
165
+ public CovariancePop covariancePop (AggregationExpression expression ) {
166
+ return covariancePop ().and (expression );
167
+ }
168
+
169
+ private CovariancePop covariancePop () {
170
+ return usesFieldRef () ? CovariancePop .covariancePopOf (fieldReference ) : CovariancePop .covariancePopOf (expression );
171
+ }
172
+
173
+ /**
174
+ * Creates new {@link AggregationExpression} that uses the previous input (field/expression) and the value of the given
175
+ * field to calculate the sample covariance of the two.
176
+ *
177
+ * @param fieldReference must not be {@literal null}.
178
+ * @return new instance of {@link CovariancePop}.
179
+ * @since 3.3
180
+ */
181
+ public CovarianceSamp covarianceSamp (String fieldReference ) {
182
+ return covarianceSamp ().and (fieldReference );
183
+ }
184
+
185
+ /**
186
+ * Creates new {@link AggregationExpression} that uses the previous input (field/expression) and the result of the given
187
+ * {@link AggregationExpression expression} to calculate the sample covariance of the two.
188
+ *
189
+ * @param expression must not be {@literal null}.
190
+ * @return new instance of {@link CovariancePop}.
191
+ * @since 3.3
192
+ */
193
+ public CovarianceSamp covarianceSamp (AggregationExpression expression ) {
194
+ return covarianceSamp ().and (expression );
195
+ }
196
+
197
+ private CovarianceSamp covarianceSamp () {
198
+ return usesFieldRef () ? CovarianceSamp .covarianceSampOf (fieldReference )
199
+ : CovarianceSamp .covarianceSampOf (expression );
200
+ }
201
+
145
202
private boolean usesFieldRef () {
146
203
return fieldReference != null ;
147
204
}
@@ -658,4 +715,124 @@ public Document toDocument(Object value, AggregationOperationContext context) {
658
715
return super .toDocument (value , context );
659
716
}
660
717
}
718
+
719
+ /**
720
+ * {@link AggregationExpression} for {@code $covariancePop}.
721
+ *
722
+ * @author Christoph Strobl
723
+ * @since 3.3
724
+ */
725
+ public static class CovariancePop extends AbstractAggregationExpression {
726
+
727
+ private CovariancePop (Object value ) {
728
+ super (value );
729
+ }
730
+
731
+ /**
732
+ * Creates new {@link CovariancePop}.
733
+ *
734
+ * @param fieldReference must not be {@literal null}.
735
+ * @return new instance of {@link CovariancePop}.
736
+ */
737
+ public static CovariancePop covariancePopOf (String fieldReference ) {
738
+
739
+ Assert .notNull (fieldReference , "FieldReference must not be null!" );
740
+ return new CovariancePop (asFields (fieldReference ));
741
+ }
742
+
743
+ /**
744
+ * Creates new {@link CovariancePop}.
745
+ *
746
+ * @param expression must not be {@literal null}.
747
+ * @return new instance of {@link CovariancePop}.
748
+ */
749
+ public static CovariancePop covariancePopOf (AggregationExpression expression ) {
750
+ return new CovariancePop (Collections .singletonList (expression ));
751
+ }
752
+
753
+ /**
754
+ * Creates new {@link CovariancePop} with all previously added arguments appending the given one.
755
+ *
756
+ * @param fieldReference must not be {@literal null}.
757
+ * @return new instance of {@link CovariancePop}.
758
+ */
759
+ public CovariancePop and (String fieldReference ) {
760
+ return new CovariancePop (append (asFields (fieldReference )));
761
+ }
762
+
763
+ /**
764
+ * Creates new {@link CovariancePop} with all previously added arguments appending the given one.
765
+ *
766
+ * @param expression must not be {@literal null}.
767
+ * @return new instance of {@link CovariancePop}.
768
+ */
769
+ public CovariancePop and (AggregationExpression expression ) {
770
+ return new CovariancePop (append (expression ));
771
+ }
772
+
773
+ @ Override
774
+ protected String getMongoMethod () {
775
+ return "$covariancePop" ;
776
+ }
777
+ }
778
+
779
+ /**
780
+ * {@link AggregationExpression} for {@code $covarianceSamp}.
781
+ *
782
+ * @author Christoph Strobl
783
+ * @since 3.3
784
+ */
785
+ public static class CovarianceSamp extends AbstractAggregationExpression {
786
+
787
+ private CovarianceSamp (Object value ) {
788
+ super (value );
789
+ }
790
+
791
+ /**
792
+ * Creates new {@link CovarianceSamp}.
793
+ *
794
+ * @param fieldReference must not be {@literal null}.
795
+ * @return new instance of {@link CovarianceSamp}.
796
+ */
797
+ public static CovarianceSamp covarianceSampOf (String fieldReference ) {
798
+
799
+ Assert .notNull (fieldReference , "FieldReference must not be null!" );
800
+ return new CovarianceSamp (asFields (fieldReference ));
801
+ }
802
+
803
+ /**
804
+ * Creates new {@link CovarianceSamp}.
805
+ *
806
+ * @param expression must not be {@literal null}.
807
+ * @return new instance of {@link CovarianceSamp}.
808
+ */
809
+ public static CovarianceSamp covarianceSampOf (AggregationExpression expression ) {
810
+ return new CovarianceSamp (Collections .singletonList (expression ));
811
+ }
812
+
813
+ /**
814
+ * Creates new {@link CovarianceSamp} with all previously added arguments appending the given one.
815
+ *
816
+ * @param fieldReference must not be {@literal null}.
817
+ * @return new instance of {@link CovarianceSamp}.
818
+ */
819
+ public CovarianceSamp and (String fieldReference ) {
820
+ return new CovarianceSamp (append (asFields (fieldReference )));
821
+ }
822
+
823
+ /**
824
+ * Creates new {@link CovarianceSamp} with all previously added arguments appending the given one.
825
+ *
826
+ * @param expression must not be {@literal null}.
827
+ * @return new instance of {@link CovarianceSamp}.
828
+ */
829
+ public CovarianceSamp and (AggregationExpression expression ) {
830
+ return new CovarianceSamp (append (expression ));
831
+ }
832
+
833
+ @ Override
834
+ protected String getMongoMethod () {
835
+ return "$covarianceSamp" ;
836
+ }
837
+ }
661
838
}
0 commit comments