diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperators.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperators.java index 0fbfcac411..ca43b2750b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperators.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperators.java @@ -799,6 +799,26 @@ public Cosh cosh() { public Cosh cosh(AngularUnit unit) { return usesFieldRef() ? Cosh.coshOf(fieldReference, unit) : Cosh.coshOf(expression, unit); } + + /** + * Creates new {@link AggregationExpression} that calculates the inverse cosine of a numeric value. + * + * @return new instance of {@link ACos}. + * @since 3.3 + */ + public ACos acos() { + return usesFieldRef() ? ACos.acosOf(fieldReference) : ACos.acosOf(expression); + } + + /** + * Creates new {@link AggregationExpression} that calculates the inverse hyperbolic cosine of a numeric value. + * + * @return new instance of {@link ACosh}. + * @since 3.3 + */ + public ACosh acosh() { + return usesFieldRef() ? ACosh.acoshOf(fieldReference) : ACosh.acoshOf(expression); + } /** * Creates new {@link AggregationExpression} that calculates the tangent of a numeric value given in @@ -2664,6 +2684,104 @@ protected String getMongoMethod() { return "$cosh"; } } + + /** + * An {@link AggregationExpression expression} that calculates the inverse cosine of a value. + * + */ + public static class ACos extends AbstractAggregationExpression { + + private ACos(Object value) { + super(value); + } + + /** + * Creates a new {@link AggregationExpression} that calculates the inverse cosine of a value. + * + * @param fieldReference the name of the {@link Field field} that resolves to a numeric value. + * @return new instance of {@link ACos}. + */ + public static ACos acosOf(String fieldReference) { + + Assert.notNull(fieldReference, "FieldReference must not be null!"); + return new ACos(Fields.field(fieldReference)); + } + + /** + * Creates a new {@link AggregationExpression} that calculates the inverse cosine of a value. + *
+ * + * @param expression the {@link AggregationExpression expression} that resolves to a numeric value. + * @return new instance of {@link ACos}. + */ + public static ACos acosOf(AggregationExpression expression) { + return new ACos(expression); + } + + /** + * Creates a new {@link AggregationExpression} that calculates the inverse cosine of a value. + * + * @param value anything ({@link Field field}, {@link AggregationExpression expression}, ...) that resolves to a + * numeric value. + * @return new instance of {@link ACos}. + */ + public static ACos acosOf(Number value) { + return new ACos(value); + } + + @Override + protected String getMongoMethod() { + return "$acos"; + } + } + + /** + * An {@link AggregationExpression expression} that calculates the inverse hyperbolic cosine of a value + * + */ + public static class ACosh extends AbstractAggregationExpression { + + private ACosh(Object value) { + super(value); + } + + /** + * Creates a new {@link AggregationExpression} that calculates the inverse hyperbolic cosine of a value. + * + * @param fieldReference the name of the {@link Field field} that resolves to a numeric value. + * @return new instance of {@link ACosh}. + */ + public static ACosh acoshOf(String fieldReference) { + return new ACosh(Fields.field(fieldReference)); + } + + /** + * Creates a new {@link AggregationExpression} that calculates the inverse hyperbolic cosine of a value. + *
+ * + * @param expression the {@link AggregationExpression expression} that resolves to a numeric value. + * @return new instance of {@link ACosh}. + */ + public static ACosh acoshOf(AggregationExpression expression) { + return new ACosh(expression); + } + + /** + * Creates a new {@link AggregationExpression} that calculates the inverse hyperbolic cosine of a value. + * + * @param value anything ({@link Field field}, {@link AggregationExpression expression}, ...) that resolves to a + * numeric value. + * @return new instance of {@link ACosh}. + */ + public static ACosh acoshOf(Object value) { + return new ACosh(value); + } + + @Override + protected String getMongoMethod() { + return "$acosh"; + } + } /** * An {@link AggregationExpression expression} that calculates the tangent of a value that is measured in radians. diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperatorsUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperatorsUnitTests.java index ab3d1c2400..6dbb3b3a6c 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperatorsUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperatorsUnitTests.java @@ -138,6 +138,16 @@ void rendersCosh() { assertThat(valueOf("angle").cosh().toDocument(Aggregation.DEFAULT_CONTEXT)).isEqualTo("{ $cosh : \"$angle\" }"); } + + @Test + void rendersACos() { + assertThat(valueOf("field").acos().toDocument(Aggregation.DEFAULT_CONTEXT)).isEqualTo("{ $acos : \"$field\" }"); + } + + @Test + void rendersACosh() { + assertThat(valueOf("field").acosh().toDocument(Aggregation.DEFAULT_CONTEXT)).isEqualTo("{ $acosh : \"$field\" }"); + } @Test // GH-3710 void rendersCoshWithValueInDegrees() {