Skip to content

Commit fe3a131

Browse files
committed
added comments explaining the Comparable interface
1 parent ca9f416 commit fe3a131

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/AggregatePath.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@
3232
import org.springframework.data.mapping.PersistentPropertyPath;
3333
import org.springframework.data.mapping.PropertyHandler;
3434
import org.springframework.data.relational.core.sql.SqlIdentifier;
35+
import org.springframework.lang.NonNull;
3536
import org.springframework.lang.Nullable;
3637
import org.springframework.util.Assert;
3738

3839
/**
3940
* Represents a path within an aggregate starting from the aggregate root. The path can be iterated from the leaf to its
4041
* root.
4142
*
43+
* It implements {@link Comparable} so that collections of {@code AggregatePath} instances can be sorted in a consistent way.
44+
*
4245
* @author Jens Schauder
4346
* @author Mark Paluch
4447
* @since 3.2
@@ -264,6 +267,20 @@ default Stream<AggregatePath> stream() {
264267
@Nullable
265268
AggregatePath subtract(@Nullable AggregatePath basePath);
266269

270+
/**
271+
* Compares this {@code AggregatePath} to another {@code AggregatePath} based on their dot path notation.
272+
* <p>
273+
* This is used to get {@code AggregatePath} instances sorted in a consistent way. Since this order affects generated SQL this also affects query caches and similar.
274+
*
275+
* @param other the {@code AggregatePath} to compare to. Must not be {@literal null}.
276+
* @return a negative integer, zero, or a positive integer as this object's path is less than,
277+
* equal to, or greater than the specified object's path.
278+
*/
279+
@Override
280+
default int compareTo(@NonNull AggregatePath other) {
281+
return toDotPath().compareTo(other.toDotPath());
282+
}
283+
267284
/**
268285
* Information about a table underlying an entity.
269286
*

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/DefaultAggregatePath.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,6 @@ public String toString() {
303303
+ ((isRoot()) ? "/" : path.toDotPath());
304304
}
305305

306-
@Override
307-
public int compareTo(@NonNull AggregatePath other) {
308-
return toDotPath().compareTo(other.toDotPath());
309-
}
310-
311306
private static class AggregatePathIterator implements Iterator<AggregatePath> {
312307

313308
private @Nullable AggregatePath current;

0 commit comments

Comments
 (0)