@@ -54,9 +54,6 @@ public abstract class SortHandlerMethodArgumentResolverSupport {
5454 private static final String DEFAULT_QUALIFIER_DELIMITER = "_" ;
5555 private static final Sort DEFAULT_SORT = Sort .unsorted ();
5656
57- private static final String SORT_DEFAULTS_NAME = SortDefaults .class .getSimpleName ();
58- private static final String SORT_DEFAULT_NAME = SortDefault .class .getSimpleName ();
59-
6057 private Sort fallbackSort = DEFAULT_SORT ;
6158 private String sortParameter = DEFAULT_PARAMETER ;
6259 private String propertyDelimiter = DEFAULT_PROPERTY_DELIMITER ;
@@ -165,17 +162,21 @@ private Sort appendOrCreateSortTo(MergedAnnotation<SortDefault> sortDefault, Sor
165162 }
166163
167164 List <Order > orders = new ArrayList <>(fields .length );
165+ Direction direction = sortDefault .getEnum ("direction" , Direction .class );
166+ NullHandling nullHandling = sortDefault .getEnum ("nullHandling" , NullHandling .class );
167+ boolean caseSensitive = sortDefault .getBoolean ("caseSensitive" );
168+
168169 for (String field : fields ) {
169170
170- Order order = new Order (sortDefault . getEnum ( " direction" , Direction . class ) , field );
171+ Order order = new Order (direction , field );
171172
172- order = switch (sortDefault . getEnum ( " nullHandling" , NullHandling . class ) ) {
173+ order = switch (nullHandling ) {
173174 case NATIVE -> order .nullsNative ();
174175 case NULLS_FIRST -> order .nullsFirst ();
175176 case NULLS_LAST -> order .nullsLast ();
176177 };
177178
178- orders .add (sortDefault . getBoolean ( " caseSensitive" ) ? order : order .ignoreCase ());
179+ orders .add (caseSensitive ? order : order .ignoreCase ());
179180 }
180181
181182 return sortOrNull .and (Sort .by (orders ));
@@ -223,7 +224,6 @@ Sort parseParameterIntoSort(List<String> source, String delimiter) {
223224 }
224225
225226 SortOrderParser .parse (part , delimiter ) //
226- .parseNullHandling () //
227227 .parseIgnoreCase () //
228228 .parseDirection () //
229229 .forEachOrder (allOrders ::add );
@@ -370,28 +370,23 @@ List<String> dumpExpressionIfPresentInto(List<String> expressions) {
370370 static class SortOrderParser {
371371
372372 private static final String IGNORECASE = "ignorecase" ;
373- private static final String NULLSNATIVE = "nullsnative" ;
374- private static final String NULLSFIRST = "nullsfirst" ;
375- private static final String NULLSLAST = "nullslast" ;
376373
377374 private final String [] elements ;
378375 private final int lastIndex ;
379376 private final Optional <Direction > direction ;
380377 private final Optional <Boolean > ignoreCase ;
381- private final Optional <NullHandling > nullHandling ;
382378
383379 private SortOrderParser (String [] elements ) {
384- this (elements , elements .length , Optional .empty (), Optional .empty (), Optional . empty () );
380+ this (elements , elements .length , Optional .empty (), Optional .empty ());
385381 }
386382
387383 private SortOrderParser (String [] elements , int lastIndex , Optional <Direction > direction ,
388- Optional <Boolean > ignoreCase , Optional < NullHandling > nullHandling ) {
384+ Optional <Boolean > ignoreCase ) {
389385
390386 this .elements = elements ;
391387 this .lastIndex = Math .max (0 , lastIndex );
392388 this .direction = direction ;
393389 this .ignoreCase = ignoreCase ;
394- this .nullHandling = nullHandling ;
395390 }
396391
397392 /**
@@ -410,21 +405,6 @@ public static SortOrderParser parse(String part, String delimiter) {
410405 return new SortOrderParser (elements );
411406 }
412407
413- /**
414- * Parse the {@link NullHandling} portion of the sort specification.
415- *
416- * @return a new parsing state object.
417- */
418- public SortOrderParser parseNullHandling () {
419-
420- Optional <NullHandling > nullHandling = lastIndex > 0 ?
421- fromOptionalNullHandlingString (elements [lastIndex - 1 ]) :
422- Optional .empty ();
423-
424- return new SortOrderParser (elements , lastIndex - (nullHandling .isPresent () ? 1 : 0 ), direction , ignoreCase ,
425- nullHandling );
426- }
427-
428408 /**
429409 * Parse the {@code ignoreCase} portion of the sort specification.
430410 *
@@ -436,8 +416,7 @@ public SortOrderParser parseIgnoreCase() {
436416 fromOptionalIgnoreCaseString (elements [lastIndex - 1 ]) :
437417 Optional .empty ();
438418
439- return new SortOrderParser (elements , lastIndex - (ignoreCase .isPresent () ? 1 : 0 ), direction , ignoreCase ,
440- nullHandling );
419+ return new SortOrderParser (elements , lastIndex - (ignoreCase .isPresent () ? 1 : 0 ), direction , ignoreCase );
441420 }
442421
443422 /**
@@ -450,8 +429,7 @@ public SortOrderParser parseDirection() {
450429 Optional <Direction > direction = lastIndex > 0 ? Direction .fromOptionalString (elements [lastIndex - 1 ])
451430 : Optional .empty ();
452431
453- return new SortOrderParser (elements , lastIndex - (direction .isPresent () ? 1 : 0 ), direction , ignoreCase ,
454- nullHandling );
432+ return new SortOrderParser (elements , lastIndex - (direction .isPresent () ? 1 : 0 ), direction , ignoreCase );
455433 }
456434
457435 /**
@@ -466,23 +444,6 @@ public void forEachOrder(Consumer<? super Order> callback) {
466444 }
467445 }
468446
469- private Optional <NullHandling > fromOptionalNullHandlingString (String value ) {
470-
471- if (NULLSNATIVE .equalsIgnoreCase (value )) {
472- return Optional .of (NullHandling .NATIVE );
473- }
474-
475- if (NULLSFIRST .equalsIgnoreCase (value )) {
476- return Optional .of (NullHandling .NULLS_FIRST );
477- }
478-
479- if (NULLSLAST .equalsIgnoreCase (value )) {
480- return Optional .of (NullHandling .NULLS_LAST );
481- }
482-
483- return Optional .empty ();
484- }
485-
486447 private Optional <Boolean > fromOptionalIgnoreCaseString (String value ) {
487448 return IGNORECASE .equalsIgnoreCase (value ) ? Optional .of (true ) : Optional .empty ();
488449 }
@@ -495,14 +456,6 @@ private Optional<Order> toOrder(String property) {
495456
496457 Order order = direction .map (it -> new Order (it , property )).orElseGet (() -> Order .by (property ));
497458
498- if (nullHandling .isPresent ()) {
499- order = switch (nullHandling .get ()) {
500- case NATIVE -> order .nullsNative ();
501- case NULLS_FIRST -> order .nullsFirst ();
502- case NULLS_LAST -> order .nullsLast ();
503- };
504- }
505-
506459 if (ignoreCase .isPresent ()) {
507460 return Optional .of (order .ignoreCase ());
508461 }
0 commit comments