DATACMNS-867 - Moved to new factory methods for Sort.
Codebase now uses Sort.by(…) where possible instead of the deprecated new Sort(…).
This commit is contained in:
@@ -55,7 +55,7 @@ public class PageRequest extends AbstractPageRequest {
|
||||
*/
|
||||
@Deprecated
|
||||
public PageRequest(int page, int size, Direction direction, String... properties) {
|
||||
this(page, size, new Sort(direction, properties));
|
||||
this(page, size, Sort.by(direction, properties));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +83,7 @@ public class PageRequest extends AbstractPageRequest {
|
||||
}
|
||||
|
||||
public static PageRequest of(int page, int size, Direction direction, String... properties) {
|
||||
return of(page, size, new Sort(direction, properties));
|
||||
return of(page, size, Sort.by(direction, properties));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -39,7 +39,7 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order
|
||||
|
||||
private static final long serialVersionUID = 5737186511678863905L;
|
||||
|
||||
private static final Sort UNSORTED = new Sort(new Order[0]);
|
||||
private static final Sort UNSORTED = Sort.by(new Order[0]);
|
||||
|
||||
public static final Direction DEFAULT_DIRECTION = Direction.ASC;
|
||||
|
||||
@@ -93,7 +93,7 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order
|
||||
/**
|
||||
* Creates a new {@link Sort} instance.
|
||||
*
|
||||
* @param direction defaults to {@linke Sort#DEFAULT_DIRECTION} (for {@literal null} cases, too)
|
||||
* @param direction defaults to {@link Sort#DEFAULT_DIRECTION} (for {@literal null} cases, too)
|
||||
* @param properties must not be {@literal null} or contain {@literal null} or empty strings.
|
||||
*/
|
||||
public Sort(Direction direction, List<String> properties) {
|
||||
@@ -148,6 +148,24 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order
|
||||
return new Sort(orders);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Sort} for the given {@link Order}s.
|
||||
*
|
||||
* @param direction must not be {@literal null}.
|
||||
* @param properties must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public static Sort by(Direction direction, String... properties) {
|
||||
|
||||
Assert.notNull(direction, "Direction must not be null!");
|
||||
Assert.notNull(properties, "Properties must not be null!");
|
||||
Assert.isTrue(properties.length > 0, "At least one property must be given!");
|
||||
|
||||
return Sort.by(Arrays.stream(properties)//
|
||||
.map(it -> new Order(direction, it))//
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Sort} instances representing no sorting setup at all.
|
||||
*
|
||||
@@ -419,6 +437,10 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order
|
||||
this(DEFAULT_DIRECTION, property);
|
||||
}
|
||||
|
||||
public static Order by(String property) {
|
||||
return new Order(property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Order} instance. if order is {@literal null} then order defaults to
|
||||
* {@link Sort#DEFAULT_DIRECTION}
|
||||
@@ -515,7 +537,7 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order
|
||||
* @return
|
||||
*/
|
||||
public Sort withProperties(String... properties) {
|
||||
return new Sort(this.direction, properties);
|
||||
return Sort.by(this.direction, properties);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user