@@ -350,19 +350,19 @@ public SortArray sort(Sort sort) {
350350 }
351351
352352 /**
353- * Creates new {@link AggregationExpression} that takes the associated array and sorts it by the given {@link Sort
354- * order}.
353+ * Creates new {@link AggregationExpression} that takes the associated array and sorts it by the given
354+ * {@link Direction order}.
355355 *
356356 * @return new instance of {@link SortArray}.
357- * @since 4.0
357+ * @since 4.5
358358 */
359359 public SortArray sort (Direction direction ) {
360360
361361 if (usesFieldRef ()) {
362- return SortArray .sortArrayOf (fieldReference ).by (direction );
362+ return SortArray .sortArrayOf (fieldReference ).direction (direction );
363363 }
364364
365- return (usesExpression () ? SortArray .sortArrayOf (expression ) : SortArray .sortArray (values )).by (direction );
365+ return (usesExpression () ? SortArray .sortArrayOf (expression ) : SortArray .sortArray (values )).direction (direction );
366366 }
367367
368368 /**
@@ -1998,10 +1998,6 @@ public static First firstOf(AggregationExpression expression) {
19981998 return new First (expression );
19991999 }
20002000
2001- /*
2002- * (non-Javadoc)
2003- * @see org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression#getMongoMethod()
2004- */
20052001 @ Override
20062002 protected String getMongoMethod () {
20072003 return "$first" ;
@@ -2052,10 +2048,6 @@ public static Last lastOf(AggregationExpression expression) {
20522048 return new Last (expression );
20532049 }
20542050
2055- /*
2056- * (non-Javadoc)
2057- * @see org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression#getMongoMethod()
2058- */
20592051 @ Override
20602052 protected String getMongoMethod () {
20612053 return "$last" ;
@@ -2116,41 +2108,38 @@ public SortArray by(Sort sort) {
21162108 }
21172109
21182110 /**
2119- * Sort the array elements by their values in ascending order. Suitable for arrays of simple types (e.g., integers,
2120- * strings).
2111+ * Order the values for the array in the given direction.
21212112 *
2113+ * @param direction must not be {@literal null}.
21222114 * @return new instance of {@link SortArray}.
2123- * @since 4.x (TBD)
2115+ * @since 4.5
21242116 */
2125- public SortArray byValueAscending ( ) {
2126- return new SortArray (append ("sortBy" , 1 ));
2117+ public SortArray direction ( Direction direction ) {
2118+ return new SortArray (append ("sortBy" , direction . isAscending () ? 1 : - 1 ));
21272119 }
21282120
21292121 /**
2130- * Sort the array elements by their values in descending order. Suitable for arrays of simple types (e.g., integers,
2122+ * Sort the array elements by their values in ascending order. Suitable for arrays of simple types (e.g., integers,
21312123 * strings).
21322124 *
21332125 * @return new instance of {@link SortArray}.
2134- * @since 4.x (TBD)
2126+ * @since 4.5
21352127 */
2136- public SortArray byValueDescending () {
2137- return new SortArray ( append ( "sortBy" , - 1 ) );
2128+ public SortArray byValueAscending () {
2129+ return direction ( Direction . ASC );
21382130 }
21392131
21402132 /**
2141- * Set the order to put elements in.
2133+ * Sort the array elements by their values in descending order. Suitable for arrays of simple types (e.g., integers,
2134+ * strings).
21422135 *
2143- * @param direction must not be {@literal null}.
21442136 * @return new instance of {@link SortArray}.
2137+ * @since 4.5
21452138 */
2146- public SortArray by ( Direction direction ) {
2147- return new SortArray ( append ( "sortBy" , direction . isAscending () ? 1 : - 1 ) );
2139+ public SortArray byValueDescending ( ) {
2140+ return direction ( Direction . DESC );
21482141 }
21492142
2150- /*
2151- * (non-Javadoc)
2152- * @see org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression#getMongoMethod()
2153- */
21542143 @ Override
21552144 protected String getMongoMethod () {
21562145 return "$sortArray" ;
0 commit comments