@@ -338,19 +338,19 @@ public SortArray sort(Sort sort) {
338
338
}
339
339
340
340
/**
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}.
343
343
*
344
344
* @return new instance of {@link SortArray}.
345
- * @since 4.0
345
+ * @since 4.5
346
346
*/
347
347
public SortArray sort (Direction direction ) {
348
348
349
349
if (usesFieldRef ()) {
350
- return SortArray .sortArrayOf (fieldReference ).by (direction );
350
+ return SortArray .sortArrayOf (fieldReference ).direction (direction );
351
351
}
352
352
353
- return (usesExpression () ? SortArray .sortArrayOf (expression ) : SortArray .sortArray (values )).by (direction );
353
+ return (usesExpression () ? SortArray .sortArrayOf (expression ) : SortArray .sortArray (values )).direction (direction );
354
354
}
355
355
356
356
/**
@@ -1960,10 +1960,6 @@ public static First firstOf(AggregationExpression expression) {
1960
1960
return new First (expression );
1961
1961
}
1962
1962
1963
- /*
1964
- * (non-Javadoc)
1965
- * @see org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression#getMongoMethod()
1966
- */
1967
1963
@ Override
1968
1964
protected String getMongoMethod () {
1969
1965
return "$first" ;
@@ -2014,10 +2010,6 @@ public static Last lastOf(AggregationExpression expression) {
2014
2010
return new Last (expression );
2015
2011
}
2016
2012
2017
- /*
2018
- * (non-Javadoc)
2019
- * @see org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression#getMongoMethod()
2020
- */
2021
2013
@ Override
2022
2014
protected String getMongoMethod () {
2023
2015
return "$last" ;
@@ -2077,41 +2069,38 @@ public SortArray by(Sort sort) {
2077
2069
}
2078
2070
2079
2071
/**
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.
2082
2073
*
2074
+ * @param direction must not be {@literal null}.
2083
2075
* @return new instance of {@link SortArray}.
2084
- * @since 4.x (TBD)
2076
+ * @since 4.5
2085
2077
*/
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 ));
2088
2080
}
2089
2081
2090
2082
/**
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,
2092
2084
* strings).
2093
2085
*
2094
2086
* @return new instance of {@link SortArray}.
2095
- * @since 4.x (TBD)
2087
+ * @since 4.5
2096
2088
*/
2097
- public SortArray byValueDescending () {
2098
- return new SortArray ( append ( "sortBy" , - 1 ) );
2089
+ public SortArray byValueAscending () {
2090
+ return direction ( Direction . ASC );
2099
2091
}
2100
2092
2101
2093
/**
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).
2103
2096
*
2104
- * @param direction must not be {@literal null}.
2105
2097
* @return new instance of {@link SortArray}.
2098
+ * @since 4.5
2106
2099
*/
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 );
2109
2102
}
2110
2103
2111
- /*
2112
- * (non-Javadoc)
2113
- * @see org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression#getMongoMethod()
2114
- */
2115
2104
@ Override
2116
2105
protected String getMongoMethod () {
2117
2106
return "$sortArray" ;
0 commit comments