29
29
* {@literal null} or empty strings. The direction defaults to {@link Sort#DEFAULT_DIRECTION}.
30
30
*
31
31
* @author Oliver Gierke
32
+ * @author Thomas Darimont
32
33
*/
33
34
public class Sort implements Iterable <org .springframework .data .domain .Sort .Order >, Serializable {
34
35
@@ -233,24 +234,24 @@ public static Direction fromStringOrNull(String value) {
233
234
* Enumeration for null handling hints that can be used in {@link Order} expressions.
234
235
*
235
236
* @author Thomas Darimont
236
- * @since 1.7
237
+ * @since 1.8
237
238
*/
238
239
public static enum NullHandling {
239
240
240
241
/**
241
242
* Lets the data store decide what to do with nulls.
242
243
*/
243
- NATIVE , //
244
+ NATIVE ,
244
245
245
246
/**
246
247
* A hint to the used data store to order entries with null values before non null entries.
247
248
*/
248
- NULLS_FIRST , //
249
+ NULLS_FIRST ,
249
250
250
251
/**
251
252
* A hint to the used data store to order entries with null values after non null entries.
252
253
*/
253
- NULLS_LAST ; //
254
+ NULLS_LAST ;
254
255
}
255
256
256
257
/**
@@ -268,7 +269,7 @@ public static class Order implements Serializable {
268
269
private final Direction direction ;
269
270
private final String property ;
270
271
private final boolean ignoreCase ;
271
- private final NullHandling nullHandlingHint ;
272
+ private final NullHandling nullHandling ;
272
273
273
274
/**
274
275
* Creates a new {@link Order} instance. if order is {@literal null} then order defaults to
@@ -278,7 +279,6 @@ public static class Order implements Serializable {
278
279
* @param property must not be {@literal null} or empty.
279
280
*/
280
281
public Order (Direction direction , String property ) {
281
-
282
282
this (direction , property , DEFAULT_IGNORE_CASE , null );
283
283
}
284
284
@@ -288,10 +288,9 @@ public Order(Direction direction, String property) {
288
288
*
289
289
* @param direction can be {@literal null}, will default to {@link Sort#DEFAULT_DIRECTION}
290
290
* @param property must not be {@literal null} or empty.
291
- * @param nullHandlingHint can be {@literal null}, will default to {@link NullHandling#NATIVE}.
291
+ * @param nullHandling can be {@literal null}, will default to {@link NullHandling#NATIVE}.
292
292
*/
293
293
public Order (Direction direction , String property , NullHandling nullHandlingHint ) {
294
-
295
294
this (direction , property , DEFAULT_IGNORE_CASE , nullHandlingHint );
296
295
}
297
296
@@ -312,10 +311,10 @@ public Order(String property) {
312
311
* @param direction can be {@literal null}, will default to {@link Sort#DEFAULT_DIRECTION}
313
312
* @param property must not be {@literal null} or empty.
314
313
* @param ignoreCase true if sorting should be case insensitive. false if sorting should be case sensitive.
315
- * @param nullHandlingHint can be {@literal null}, will default to {@link NullHandling#NATIVE}.
314
+ * @param nullHandling can be {@literal null}, will default to {@link NullHandling#NATIVE}.
316
315
* @since 1.7
317
316
*/
318
- private Order (Direction direction , String property , boolean ignoreCase , NullHandling nullHandlingHint ) {
317
+ private Order (Direction direction , String property , boolean ignoreCase , NullHandling nullHandling ) {
319
318
320
319
if (!StringUtils .hasText (property )) {
321
320
throw new IllegalArgumentException ("Property must not null or empty!" );
@@ -324,7 +323,7 @@ private Order(Direction direction, String property, boolean ignoreCase, NullHand
324
323
this .direction = direction == null ? DEFAULT_DIRECTION : direction ;
325
324
this .property = property ;
326
325
this .ignoreCase = ignoreCase ;
327
- this .nullHandlingHint = nullHandlingHint == null ? NullHandling .NATIVE : nullHandlingHint ;
326
+ this .nullHandling = nullHandling == null ? NullHandling .NATIVE : nullHandling ;
328
327
}
329
328
330
329
/**
@@ -383,7 +382,7 @@ public boolean isIgnoreCase() {
383
382
* @return
384
383
*/
385
384
public Order with (Direction order ) {
386
- return new Order (order , this .property , nullHandlingHint );
385
+ return new Order (order , this .property , nullHandling );
387
386
}
388
387
389
388
/**
@@ -402,28 +401,28 @@ public Sort withProperties(String... properties) {
402
401
* @return
403
402
*/
404
403
public Order ignoreCase () {
405
- return new Order (direction , property , true , nullHandlingHint );
404
+ return new Order (direction , property , true , nullHandling );
406
405
}
407
406
408
407
/**
409
408
* Returns a {@link Order} with the given {@link NullHandling}.
410
409
*
411
- * @param nullHandling
410
+ * @param nullHandling can be {@literal null}.
412
411
* @return
413
- * @since 1.7
412
+ * @since 1.8
414
413
*/
415
- public Order withNullHandling (NullHandling nullHandling ) {
414
+ public Order with (NullHandling nullHandling ) {
416
415
return new Order (direction , this .property , ignoreCase , nullHandling );
417
416
}
418
417
419
418
/**
420
419
* Returns a {@link Order} with {@link NullHandling#NULLS_FIRST} as null handling hint.
421
420
*
422
421
* @return
423
- * @since 1.7
422
+ * @since 1.8
424
423
*/
425
424
public Order nullsFirst () {
426
- return withNullHandling (NullHandling .NULLS_FIRST );
425
+ return with (NullHandling .NULLS_FIRST );
427
426
}
428
427
429
428
/**
@@ -433,7 +432,7 @@ public Order nullsFirst() {
433
432
* @since 1.7
434
433
*/
435
434
public Order nullsLast () {
436
- return withNullHandling (NullHandling .NULLS_LAST );
435
+ return with (NullHandling .NULLS_LAST );
437
436
}
438
437
439
438
/**
@@ -443,7 +442,7 @@ public Order nullsLast() {
443
442
* @since 1.7
444
443
*/
445
444
public Order nullsNative () {
446
- return withNullHandling (NullHandling .NATIVE );
445
+ return with (NullHandling .NATIVE );
447
446
}
448
447
449
448
/**
@@ -452,8 +451,8 @@ public Order nullsNative() {
452
451
* @return
453
452
* @since 1.7
454
453
*/
455
- public NullHandling getNullHandlingHint () {
456
- return nullHandlingHint ;
454
+ public NullHandling getNullHandling () {
455
+ return nullHandling ;
457
456
}
458
457
459
458
/*
@@ -468,7 +467,7 @@ public int hashCode() {
468
467
result = 31 * result + direction .hashCode ();
469
468
result = 31 * result + property .hashCode ();
470
469
result = 31 * result + (ignoreCase ? 1 : 0 );
471
- result = 31 * result + ( nullHandlingHint .hashCode () );
470
+ result = 31 * result + nullHandling .hashCode ();
472
471
473
472
return result ;
474
473
}
@@ -491,7 +490,7 @@ public boolean equals(Object obj) {
491
490
Order that = (Order ) obj ;
492
491
493
492
return this .direction .equals (that .direction ) && this .property .equals (that .property )
494
- && this .ignoreCase == that .ignoreCase && this .nullHandlingHint .equals (that .nullHandlingHint );
493
+ && this .ignoreCase == that .ignoreCase && this .nullHandling .equals (that .nullHandling );
495
494
}
496
495
497
496
/*
@@ -503,8 +502,8 @@ public String toString() {
503
502
504
503
String result = String .format ("%s: %s" , property , direction );
505
504
506
- if (!NullHandling .NATIVE .equals (nullHandlingHint )) {
507
- result += ", " + nullHandlingHint ;
505
+ if (!NullHandling .NATIVE .equals (nullHandling )) {
506
+ result += ", " + nullHandling ;
508
507
}
509
508
510
509
if (ignoreCase ) {
0 commit comments