Skip to content

Commit 00d03c5

Browse files
committedApr 24, 2024
Polishing.
Add missing Javadoc and Serial annotations. Simplify code. See #3081
·
4.0.0-M33.3.0
1 parent 7bac883 commit 00d03c5

File tree

2 files changed

+67
-60
lines changed

2 files changed

+67
-60
lines changed
 

‎src/main/java/org/springframework/data/domain/Sort.java

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.domain;
1717

18+
import java.io.Serial;
1819
import java.io.Serializable;
1920
import java.util.ArrayList;
2021
import java.util.Arrays;
@@ -31,6 +32,7 @@
3132
import org.springframework.data.util.Streamable;
3233
import org.springframework.lang.Nullable;
3334
import org.springframework.util.Assert;
35+
import org.springframework.util.ObjectUtils;
3436
import org.springframework.util.StringUtils;
3537

3638
/**
@@ -45,7 +47,7 @@
4547
*/
4648
public class Sort implements Streamable<org.springframework.data.domain.Sort.Order>, Serializable {
4749

48-
private static final long serialVersionUID = 5737186511678863905L;
50+
private static final @Serial long serialVersionUID = 5737186511678863905L;
4951

5052
private static final Sort UNSORTED = Sort.by(new Order[0]);
5153

@@ -63,7 +65,7 @@ protected Sort(List<Order> orders) {
6365
* @param direction defaults to {@link Sort#DEFAULT_DIRECTION} (for {@literal null} cases, too)
6466
* @param properties must not be {@literal null} or contain {@literal null} or empty strings.
6567
*/
66-
private Sort(Direction direction, List<String> properties) {
68+
private Sort(Direction direction, @Nullable List<String> properties) {
6769

6870
if (properties == null || properties.isEmpty()) {
6971
throw new IllegalArgumentException("You have to provide at least one property to sort by");
@@ -78,7 +80,7 @@ private Sort(Direction direction, List<String> properties) {
7880
* Creates a new {@link Sort} for the given properties.
7981
*
8082
* @param properties must not be {@literal null}.
81-
* @return
83+
* @return {@link Sort} for the given properties.
8284
*/
8385
public static Sort by(String... properties) {
8486

@@ -93,7 +95,7 @@ public static Sort by(String... properties) {
9395
* Creates a new {@link Sort} for the given {@link Order}s.
9496
*
9597
* @param orders must not be {@literal null}.
96-
* @return
98+
* @return {@link Sort} for the given {@link Order}s.
9799
*/
98100
public static Sort by(List<Order> orders) {
99101

@@ -106,7 +108,7 @@ public static Sort by(List<Order> orders) {
106108
* Creates a new {@link Sort} for the given {@link Order}s.
107109
*
108110
* @param orders must not be {@literal null}.
109-
* @return
111+
* @return {@link Sort} for the given {@link Order}s.
110112
*/
111113
public static Sort by(Order... orders) {
112114

@@ -120,7 +122,7 @@ public static Sort by(Order... orders) {
120122
*
121123
* @param direction must not be {@literal null}.
122124
* @param properties must not be {@literal null}.
123-
* @return
125+
* @return {@link Sort} for the given {@link Direction} and properties.
124126
*/
125127
public static Sort by(Direction direction, String... properties) {
126128

@@ -137,7 +139,7 @@ public static Sort by(Direction direction, String... properties) {
137139
* Creates a new {@link TypedSort} for the given type.
138140
*
139141
* @param type must not be {@literal null}.
140-
* @return
142+
* @return {@link TypedSort} for the given type.
141143
* @since 2.2
142144
*/
143145
public static <T> TypedSort<T> sort(Class<T> type) {
@@ -147,7 +149,7 @@ public static <T> TypedSort<T> sort(Class<T> type) {
147149
/**
148150
* Returns a {@link Sort} instances representing no sorting setup at all.
149151
*
150-
* @return
152+
* @return unsorted Sort instance.
151153
*/
152154
public static Sort unsorted() {
153155
return UNSORTED;
@@ -156,7 +158,7 @@ public static Sort unsorted() {
156158
/**
157159
* Returns a new {@link Sort} with the current setup but descending order direction.
158160
*
159-
* @return
161+
* @return a new {@link Sort} with the current setup but descending order direction.
160162
*/
161163
public Sort descending() {
162164
return withDirection(Direction.DESC);
@@ -165,12 +167,15 @@ public Sort descending() {
165167
/**
166168
* Returns a new {@link Sort} with the current setup but ascending order direction.
167169
*
168-
* @return
170+
* @return a new {@link Sort} with the current setup but ascending order direction.
169171
*/
170172
public Sort ascending() {
171173
return withDirection(Direction.ASC);
172174
}
173175

176+
/**
177+
* @return {@literal true} if this Sort instance is sorted, {@literal false} otherwise.
178+
*/
174179
public boolean isSorted() {
175180
return !isEmpty();
176181
}
@@ -180,6 +185,9 @@ public boolean isEmpty() {
180185
return orders.isEmpty();
181186
}
182187

188+
/**
189+
* @return {@literal true} if this Sort instance is unsorted, {@literal false} otherwise.
190+
*/
183191
public boolean isUnsorted() {
184192
return !isSorted();
185193
}
@@ -189,7 +197,8 @@ public boolean isUnsorted() {
189197
* ones.
190198
*
191199
* @param sort must not be {@literal null}.
192-
* @return
200+
* @return a new {@link Sort} consisting of the {@link Order}s of the current {@link Sort} combined with the given
201+
* ones.
193202
*/
194203
public Sort and(Sort sort) {
195204

@@ -232,8 +241,8 @@ protected List<Order> doReverse() {
232241
/**
233242
* Returns the order registered for the given property.
234243
*
235-
* @param property
236-
* @return
244+
* @param property name of the property that should be sorted.
245+
* @return the sort {@link Order} or {@literal null} if the property is not sorted by.
237246
*/
238247
@Nullable
239248
public Order getOrderFor(String property) {
@@ -247,6 +256,7 @@ public Order getOrderFor(String property) {
247256
return null;
248257
}
249258

259+
@Override
250260
public Iterator<Order> iterator() {
251261
return this.orders.iterator();
252262
}
@@ -278,12 +288,6 @@ public String toString() {
278288
return isEmpty() ? "UNSORTED" : StringUtils.collectionToCommaDelimitedString(orders);
279289
}
280290

281-
/**
282-
* Creates a new {@link Sort} with the current setup but the given order direction.
283-
*
284-
* @param direction
285-
* @return
286-
*/
287291
private Sort withDirection(Direction direction) {
288292

289293
List<Order> result = new ArrayList<>(orders.size());
@@ -307,7 +311,7 @@ public enum Direction {
307311
/**
308312
* Returns whether the direction is ascending.
309313
*
310-
* @return
314+
* @return {@literal true} if ascending, {@literal false} otherwise.
311315
* @since 1.13
312316
*/
313317
public boolean isAscending() {
@@ -317,7 +321,7 @@ public boolean isAscending() {
317321
/**
318322
* Returns whether the direction is descending.
319323
*
320-
* @return
324+
* @return {@literal true} if descending, {@literal false} otherwise.
321325
* @since 1.13
322326
*/
323327
public boolean isDescending() {
@@ -327,9 +331,9 @@ public boolean isDescending() {
327331
/**
328332
* Returns the {@link Direction} enum for the given {@link String} value.
329333
*
330-
* @param value
334+
* @param value the direction name.
335+
* @return the {@link Direction} enum value for the given {@code value}.
331336
* @throws IllegalArgumentException in case the given value cannot be parsed into an enum value.
332-
* @return
333337
*/
334338
public static Direction fromString(String value) {
335339

@@ -342,15 +346,16 @@ public static Direction fromString(String value) {
342346
}
343347

344348
/**
345-
* Returns the {@link Direction} enum for the given {@link String} or empty if it cannot be parsed into an enum
346-
* value.
349+
* Returns the {@link Direction} enum for the given {@link String} or {@code Optional.empty()} if it cannot be
350+
* parsed into an enum value.
347351
*
348-
* @param value
349-
* @return
352+
* @param value the direction name.
353+
* @return Optional holding the {@link Direction} enum value or empty, if {@code value} cannot be parsed into
354+
* {@link Direction}.
350355
*/
351356
public static Optional<Direction> fromOptionalString(String value) {
352357

353-
if (value == null) {
358+
if (ObjectUtils.isEmpty(value)) {
354359
return Optional.empty();
355360
}
356361

@@ -396,7 +401,8 @@ public enum NullHandling {
396401
*/
397402
public static class Order implements Serializable {
398403

399-
private static final long serialVersionUID = 1522511010900108987L;
404+
private static final @Serial long serialVersionUID = 1522511010900108987L;
405+
400406
private static final boolean DEFAULT_IGNORE_CASE = false;
401407
private static final NullHandling DEFAULT_NULL_HANDLING = NullHandling.NATIVE;
402408

@@ -486,7 +492,7 @@ public static Order desc(String property) {
486492
/**
487493
* Returns the order the property shall be sorted for.
488494
*
489-
* @return
495+
* @return the order the property shall be sorted for.
490496
*/
491497
public Direction getDirection() {
492498
return direction;
@@ -495,7 +501,7 @@ public Direction getDirection() {
495501
/**
496502
* Returns the property to order for.
497503
*
498-
* @return
504+
* @return the property to order for.
499505
*/
500506
public String getProperty() {
501507
return property;
@@ -504,7 +510,7 @@ public String getProperty() {
504510
/**
505511
* Returns whether sorting for this property shall be ascending.
506512
*
507-
* @return
513+
* @return {@literal true} if ascending, {@literal false} otherwise.
508514
*/
509515
public boolean isAscending() {
510516
return this.direction.isAscending();
@@ -513,7 +519,7 @@ public boolean isAscending() {
513519
/**
514520
* Returns whether sorting for this property shall be descending.
515521
*
516-
* @return
522+
* @return {@literal true} if descending, {@literal false} otherwise.
517523
* @since 1.13
518524
*/
519525
public boolean isDescending() {
@@ -523,48 +529,48 @@ public boolean isDescending() {
523529
/**
524530
* Returns whether the sort will be case-sensitive or case-insensitive.
525531
*
526-
* @return
532+
* @return {@literal true} if the sort will be case-sensitive or case-insensitive, {@literal false} otherwise.
527533
*/
528534
public boolean isIgnoreCase() {
529535
return ignoreCase;
530536
}
531537

532538
/**
533-
* Returns a new {@link Order} with the given {@link Direction}.
539+
* Returns a new {@link Order} with the given {@link Direction} applied.
534540
*
535-
* @param direction
536-
* @return
541+
* @param direction the new direction to use.
542+
* @return a new {@link Order} with the given {@link Direction} applied.
537543
*/
538544
public Order with(Direction direction) {
539545
return new Order(direction, this.property, this.ignoreCase, this.nullHandling);
540546
}
541547

542548
/**
543-
* Returns a new {@link Order} with the reversed {@link #getDirection()}.
549+
* Returns a new {@link Order} with the reversed {@link #getDirection()} applied.
544550
*
545-
* @return
551+
* @return a reversed {@link Order} with the given {@link Direction} applied.
546552
* @since 3.1
547553
*/
548554
public Order reverse() {
549555
return with(this.direction == Direction.ASC ? Direction.DESC : Direction.ASC);
550556
}
551557

552558
/**
553-
* Returns a new {@link Order}
559+
* Returns a new {@link Order} with the {@code property} name applied.
554560
*
555561
* @param property must not be {@literal null} or empty.
556-
* @return
562+
* @return a new {@link Order} with the {@code property} name applied.
557563
* @since 1.13
558564
*/
559565
public Order withProperty(String property) {
560566
return new Order(this.direction, property, this.ignoreCase, this.nullHandling);
561567
}
562568

563569
/**
564-
* Returns a new {@link Sort} instance for the given properties.
570+
* Returns a new {@link Sort} instance for the given properties using {@link #getDirection()}.
565571
*
566-
* @param properties
567-
* @return
572+
* @param properties properties to sort by.
573+
* @return a new {@link Sort} instance for the given properties using {@link #getDirection()}.
568574
*/
569575
public Sort withProperties(String... properties) {
570576
return Sort.by(this.direction, properties);
@@ -573,47 +579,47 @@ public Sort withProperties(String... properties) {
573579
/**
574580
* Returns a new {@link Order} with case-insensitive sorting enabled.
575581
*
576-
* @return
582+
* @return a new {@link Order} with case-insensitive sorting enabled.
577583
*/
578584
public Order ignoreCase() {
579585
return new Order(direction, property, true, nullHandling);
580586
}
581587

582588
/**
583-
* Returns a {@link Order} with the given {@link NullHandling}.
589+
* Returns a {@link Order} with the given {@link NullHandling} applied.
584590
*
585591
* @param nullHandling can be {@literal null}.
586-
* @return
592+
* @return a new {@link Order} with the given {@link NullHandling} applied.
587593
* @since 1.8
588594
*/
589595
public Order with(NullHandling nullHandling) {
590596
return new Order(direction, this.property, ignoreCase, nullHandling);
591597
}
592598

593599
/**
594-
* Returns a {@link Order} with {@link NullHandling#NULLS_FIRST} as null handling hint.
600+
* Returns a new {@link Order} with {@link NullHandling#NULLS_FIRST} as null handling hint applied.
595601
*
596-
* @return
602+
* @return a new {@link Order} with {@link NullHandling#NULLS_FIRST} as null handling hint applied.
597603
* @since 1.8
598604
*/
599605
public Order nullsFirst() {
600606
return with(NullHandling.NULLS_FIRST);
601607
}
602608

603609
/**
604-
* Returns a {@link Order} with {@link NullHandling#NULLS_LAST} as null handling hint.
610+
* Returns a new {@link Order} with {@link NullHandling#NULLS_LAST} as null handling hint applied.
605611
*
606-
* @return
612+
* @return a new {@link Order} with {@link NullHandling#NULLS_LAST} as null handling hint applied.
607613
* @since 1.7
608614
*/
609615
public Order nullsLast() {
610616
return with(NullHandling.NULLS_LAST);
611617
}
612618

613619
/**
614-
* Returns a {@link Order} with {@link NullHandling#NATIVE} as null handling hint.
620+
* Returns a new {@link Order} with {@link NullHandling#NATIVE} as null handling hint applied.
615621
*
616-
* @return
622+
* @return a new {@link Order} with {@link NullHandling#NATIVE} as null handling hint applied.
617623
* @since 1.7
618624
*/
619625
public Order nullsNative() {
@@ -623,7 +629,7 @@ public Order nullsNative() {
623629
/**
624630
* Returns the used {@link NullHandling} hint, which can but may not be respected by the used datastore.
625631
*
626-
* @return
632+
* @return the used {@link NullHandling} hint.
627633
* @since 1.7
628634
*/
629635
public NullHandling getNullHandling() {
@@ -684,7 +690,7 @@ public String toString() {
684690
*/
685691
public static class TypedSort<T> extends Sort {
686692

687-
private static final long serialVersionUID = -3550403511206745880L;
693+
private static final @Serial long serialVersionUID = -3550403511206745880L;
688694

689695
private final Recorded<T> recorded;
690696

@@ -739,7 +745,7 @@ public Iterator<Order> iterator() {
739745

740746
@Override
741747
public boolean isEmpty() {
742-
return !recorded.getPropertyPath().isPresent();
748+
return recorded.getPropertyPath().isEmpty();
743749
}
744750

745751
@Override

‎src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -774,14 +774,15 @@ static enum PersistentPropertyFilter implements FieldFilter {
774774
UNMAPPED_PROPERTIES = Streamable.of(matches);
775775
}
776776

777+
@Override
777778
public boolean matches(Field field) {
778779

779780
if (Modifier.isStatic(field.getModifiers())) {
780781
return false;
781782
}
782783

783-
return !UNMAPPED_PROPERTIES.stream()//
784-
.anyMatch(it -> it.matches(field.getName(), field.getType()));
784+
return UNMAPPED_PROPERTIES.stream()//
785+
.noneMatch(it -> it.matches(field.getName(), field.getType()));
785786
}
786787

787788
/**
@@ -798,8 +799,8 @@ public boolean matches(Property property) {
798799
return false;
799800
}
800801

801-
return !UNMAPPED_PROPERTIES.stream()//
802-
.anyMatch(it -> it.matches(property.getName(), property.getType()));
802+
return UNMAPPED_PROPERTIES.stream()//
803+
.noneMatch(it -> it.matches(property.getName(), property.getType()));
803804
}
804805

805806
/**

0 commit comments

Comments
 (0)
Please sign in to comment.