@@ -350,19 +350,19 @@ public SortArray sort(Sort sort) {
350
350
}
351
351
352
352
/**
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}.
355
355
*
356
356
* @return new instance of {@link SortArray}.
357
- * @since 4.0
357
+ * @since 4.5
358
358
*/
359
359
public SortArray sort (Direction direction ) {
360
360
361
361
if (usesFieldRef ()) {
362
- return SortArray .sortArrayOf (fieldReference ).by (direction );
362
+ return SortArray .sortArrayOf (fieldReference ).direction (direction );
363
363
}
364
364
365
- return (usesExpression () ? SortArray .sortArrayOf (expression ) : SortArray .sortArray (values )).by (direction );
365
+ return (usesExpression () ? SortArray .sortArrayOf (expression ) : SortArray .sortArray (values )).direction (direction );
366
366
}
367
367
368
368
/**
@@ -1998,10 +1998,6 @@ public static First firstOf(AggregationExpression expression) {
1998
1998
return new First (expression );
1999
1999
}
2000
2000
2001
- /*
2002
- * (non-Javadoc)
2003
- * @see org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression#getMongoMethod()
2004
- */
2005
2001
@ Override
2006
2002
protected String getMongoMethod () {
2007
2003
return "$first" ;
@@ -2052,10 +2048,6 @@ public static Last lastOf(AggregationExpression expression) {
2052
2048
return new Last (expression );
2053
2049
}
2054
2050
2055
- /*
2056
- * (non-Javadoc)
2057
- * @see org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression#getMongoMethod()
2058
- */
2059
2051
@ Override
2060
2052
protected String getMongoMethod () {
2061
2053
return "$last" ;
@@ -2116,41 +2108,38 @@ public SortArray by(Sort sort) {
2116
2108
}
2117
2109
2118
2110
/**
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.
2121
2112
*
2113
+ * @param direction must not be {@literal null}.
2122
2114
* @return new instance of {@link SortArray}.
2123
- * @since 4.x (TBD)
2115
+ * @since 4.5
2124
2116
*/
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 ));
2127
2119
}
2128
2120
2129
2121
/**
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,
2131
2123
* strings).
2132
2124
*
2133
2125
* @return new instance of {@link SortArray}.
2134
- * @since 4.x (TBD)
2126
+ * @since 4.5
2135
2127
*/
2136
- public SortArray byValueDescending () {
2137
- return new SortArray ( append ( "sortBy" , - 1 ) );
2128
+ public SortArray byValueAscending () {
2129
+ return direction ( Direction . ASC );
2138
2130
}
2139
2131
2140
2132
/**
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).
2142
2135
*
2143
- * @param direction must not be {@literal null}.
2144
2136
* @return new instance of {@link SortArray}.
2137
+ * @since 4.5
2145
2138
*/
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 );
2148
2141
}
2149
2142
2150
- /*
2151
- * (non-Javadoc)
2152
- * @see org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression#getMongoMethod()
2153
- */
2154
2143
@ Override
2155
2144
protected String getMongoMethod () {
2156
2145
return "$sortArray" ;
0 commit comments