@@ -338,19 +338,19 @@ public SortArray sort(Sort sort) {
338338 }
339339
340340 /**
341- * Creates new {@link AggregationExpression} that takes the associated array and sorts it by the given {@link Sort
342- * order}.
341+ * Creates new {@link AggregationExpression} that takes the associated array and sorts it by the given
342+ * {@link Direction order}.
343343 *
344344 * @return new instance of {@link SortArray}.
345- * @since 4.0
345+ * @since 4.5
346346 */
347347 public SortArray sort (Direction direction ) {
348348
349349 if (usesFieldRef ()) {
350- return SortArray .sortArrayOf (fieldReference ).by (direction );
350+ return SortArray .sortArrayOf (fieldReference ).direction (direction );
351351 }
352352
353- return (usesExpression () ? SortArray .sortArrayOf (expression ) : SortArray .sortArray (values )).by (direction );
353+ return (usesExpression () ? SortArray .sortArrayOf (expression ) : SortArray .sortArray (values )).direction (direction );
354354 }
355355
356356 /**
@@ -1960,10 +1960,6 @@ public static First firstOf(AggregationExpression expression) {
19601960 return new First (expression );
19611961 }
19621962
1963- /*
1964- * (non-Javadoc)
1965- * @see org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression#getMongoMethod()
1966- */
19671963 @ Override
19681964 protected String getMongoMethod () {
19691965 return "$first" ;
@@ -2014,10 +2010,6 @@ public static Last lastOf(AggregationExpression expression) {
20142010 return new Last (expression );
20152011 }
20162012
2017- /*
2018- * (non-Javadoc)
2019- * @see org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression#getMongoMethod()
2020- */
20212013 @ Override
20222014 protected String getMongoMethod () {
20232015 return "$last" ;
@@ -2077,41 +2069,38 @@ public SortArray by(Sort sort) {
20772069 }
20782070
20792071 /**
2080- * Sort the array elements by their values in ascending order. Suitable for arrays of simple types (e.g., integers,
2081- * strings).
2072+ * Order the values for the array in the given direction.
20822073 *
2074+ * @param direction must not be {@literal null}.
20832075 * @return new instance of {@link SortArray}.
2084- * @since 4.x (TBD)
2076+ * @since 4.5
20852077 */
2086- public SortArray byValueAscending ( ) {
2087- return new SortArray (append ("sortBy" , 1 ));
2078+ public SortArray direction ( Direction direction ) {
2079+ return new SortArray (append ("sortBy" , direction . isAscending () ? 1 : - 1 ));
20882080 }
20892081
20902082 /**
2091- * Sort the array elements by their values in descending order. Suitable for arrays of simple types (e.g., integers,
2083+ * Sort the array elements by their values in ascending order. Suitable for arrays of simple types (e.g., integers,
20922084 * strings).
20932085 *
20942086 * @return new instance of {@link SortArray}.
2095- * @since 4.x (TBD)
2087+ * @since 4.5
20962088 */
2097- public SortArray byValueDescending () {
2098- return new SortArray ( append ( "sortBy" , - 1 ) );
2089+ public SortArray byValueAscending () {
2090+ return direction ( Direction . ASC );
20992091 }
21002092
21012093 /**
2102- * Set the order to put elements in.
2094+ * Sort the array elements by their values in descending order. Suitable for arrays of simple types (e.g., integers,
2095+ * strings).
21032096 *
2104- * @param direction must not be {@literal null}.
21052097 * @return new instance of {@link SortArray}.
2098+ * @since 4.5
21062099 */
2107- public SortArray by ( Direction direction ) {
2108- return new SortArray ( append ( "sortBy" , direction . isAscending () ? 1 : - 1 ) );
2100+ public SortArray byValueDescending ( ) {
2101+ return direction ( Direction . DESC );
21092102 }
21102103
2111- /*
2112- * (non-Javadoc)
2113- * @see org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression#getMongoMethod()
2114- */
21152104 @ Override
21162105 protected String getMongoMethod () {
21172106 return "$sortArray" ;
0 commit comments