Skip to content

DATAMONGO-3707 - Add support for $acos & $acosh aggregation operators #3858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4491301
Polishing.
mp911de Aug 26, 2021
2d8d66d
taking latest from main.
divyajnu08 Aug 29, 2021
037cac0
resolving merge conflict
divyajnu08 Aug 29, 2021
1010f81
Merge branch 'spring-projects-main'
divyajnu08 Aug 29, 2021
4cd6cf9
Merge branch 'spring-projects:main' into main
divyajnu08 Sep 10, 2021
3430298
Merge branch 'spring-projects:main' into main
divyajnu08 Sep 10, 2021
703b2eb
Merge branch 'spring-projects:main' into main
divyajnu08 Sep 14, 2021
825eff7
Merge branch 'spring-projects:main' into main
divyajnu08 Sep 14, 2021
853e10a
Merge branch 'spring-projects:main' into main
divyajnu08 Sep 18, 2021
e3c4202
Merge branch 'spring-projects:main' into main
divyajnu08 Sep 21, 2021
53fcdb7
Merge branch 'spring-projects:main' into main
divyajnu08 Sep 27, 2021
eb997b5
Merge branch 'spring-projects:main' into main
divyajnu08 Oct 5, 2021
0917e68
DATAMONGO-2637 - Fields and projection API are very inconvenient
divyajnu08 Sep 27, 2021
e830626
Revert "DATAMONGO-2637 - Fields and projection API are very inconveni…
divyajnu08 Sep 28, 2021
e3bdf33
DATAMONGO-2637 - Fields and projection API are very inconvenient
divyajnu08 Sep 27, 2021
857e065
Revert "DATAMONGO-2637 - Fields and projection API are very inconveni…
divyajnu08 Sep 28, 2021
e003f04
Merge branch 'spring-projects:main' into main
divyajnu08 Oct 9, 2021
a499d85
Merge branch 'main' of https://github.com/divyajnu08/spring-data-mongodb
divyajnu08 Oct 9, 2021
864bedc
DATAMONGO-3707 - Add support for $acos & $acosh aggregation operators
divyajnu08 Oct 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
* <br />
*
* @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.
* <br />
*
* @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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down