Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Refine Javadoc and update ReactivePageableHandlerMethodArgumentResolver. Fix nullability annotations.

See #3188
  • Loading branch information
mp911de committed Oct 29, 2024
1 parent 7a5e4d7 commit 24cf1fc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@

/**
* Extracts paging information from web requests and thus allows injecting {@link Pageable} instances into controller
* methods. Request properties to be parsed can be configured.
* methods. Request properties to be parsed can be configured defaulting to {@code page} for the page number and
* {@code size} for the page size.
* <p>
* Parameters can be {@link #setPrefix(String) prefixed} to disambiguate from other parameters in the request if
* necessary.
*
* @author Oliver Gierke
* @author Nick Williams
Expand All @@ -39,7 +43,8 @@ public class PageableHandlerMethodArgumentResolver extends PageableHandlerMethod
implements PageableArgumentResolver {

private static final SortHandlerMethodArgumentResolver DEFAULT_SORT_RESOLVER = new SortHandlerMethodArgumentResolver();
private SortArgumentResolver sortResolver;

private final SortArgumentResolver sortResolver;

/**
* Constructs an instance of this resolved with a default {@link SortHandlerMethodArgumentResolver}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
/**
* Base class providing methods for handler method argument resolvers to create paging information from web requests and
* thus allows injecting {@link Pageable} instances into controller methods. Request properties to be parsed can be
* configured.
* configured defaulting to {@code page} for the page number and {@code size} for the page size.
* <p>
* Parameters can be {@link #setPrefix(String) prefixed} to disambiguate from other parameters in the request if
* necessary.
*
* @author Mark Paluch
* @author Vedran Pavic
Expand Down Expand Up @@ -153,7 +156,7 @@ protected String getSizeParameterName() {
*
* @param prefix the prefix to be used or {@literal null} to reset to the default.
*/
public void setPrefix(String prefix) {
public void setPrefix(@Nullable String prefix) {
this.prefix = prefix == null ? DEFAULT_PREFIX : prefix;
}

Expand All @@ -163,7 +166,7 @@ public void setPrefix(String prefix) {
*
* @param qualifierDelimiter the delimiter to be used or {@literal null} to reset to the default.
*/
public void setQualifierDelimiter(String qualifierDelimiter) {
public void setQualifierDelimiter(@Nullable String qualifierDelimiter) {
this.qualifierDelimiter = qualifierDelimiter == null ? DEFAULT_QUALIFIER_DELIMITER : qualifierDelimiter;
}

Expand Down Expand Up @@ -198,7 +201,7 @@ protected Pageable getPageable(MethodParameter methodParameter, @Nullable String
Optional<Integer> page = parseAndApplyBoundaries(pageString, Integer.MAX_VALUE, true);
Optional<Integer> pageSize = parseAndApplyBoundaries(pageSizeString, maxPageSize, false);

if (!(page.isPresent() && pageSize.isPresent()) && !defaultOrFallback.isPresent()) {
if (!(page.isPresent() && pageSize.isPresent()) && defaultOrFallback.isEmpty()) {
return Pageable.unpaged();
}

Expand All @@ -210,7 +213,7 @@ protected Pageable getPageable(MethodParameter methodParameter, @Nullable String
// Limit lower bound
ps = ps < 1 ? defaultOrFallback.map(Pageable::getPageSize).orElseThrow(IllegalStateException::new) : ps;
// Limit upper bound
ps = ps > maxPageSize ? maxPageSize : ps;
ps = Math.min(ps, maxPageSize);

return PageRequest.of(p, ps, defaultOrFallback.map(Pageable::getSort).orElseGet(Sort::unsorted));
}
Expand Down Expand Up @@ -286,7 +289,7 @@ private Optional<Integer> parseAndApplyBoundaries(@Nullable String parameter, in

try {
int parsed = Integer.parseInt(parameter) - (oneIndexedParameters && shiftIndex ? 1 : 0);
return Optional.of(parsed < 0 ? 0 : parsed > upper ? upper : parsed);
return Optional.of(parsed < 0 ? 0 : Math.min(parsed, upper));
} catch (NumberFormatException e) {
return Optional.of(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@

/**
* Extracts paging information from web requests and thus allows injecting {@link Pageable} instances into WebFlux
* controller methods. Request properties to be parsed can be configured. Default configuration uses request parameters
* beginning with {@link #DEFAULT_PAGE_PARAMETER}{@link #DEFAULT_QUALIFIER_DELIMITER}.
* controller methods. Request properties to be parsed can be configured defaulting to {@code page} for the page number
* and {@code size} for the page size.
* <p>
* Parameters can be {@link #setPrefix(String) prefixed} to disambiguate from other parameters in the request if
* necessary.
*
* @since 2.2
* @author Mark Paluch
Expand All @@ -40,7 +43,7 @@ public class ReactivePageableHandlerMethodArgumentResolver extends PageableHandl

private static final ReactiveSortHandlerMethodArgumentResolver DEFAULT_SORT_RESOLVER = new ReactiveSortHandlerMethodArgumentResolver();

private ReactiveSortHandlerMethodArgumentResolver sortResolver;
private final ReactiveSortHandlerMethodArgumentResolver sortResolver;

/**
* Constructs an instance of this resolved with a default {@link ReactiveSortHandlerMethodArgumentResolver}.
Expand Down

0 comments on commit 24cf1fc

Please sign in to comment.