
win.doyto.query.core.PageQuery Maven / Gradle / Ivy
// Generated by delombok at Sat Aug 10 11:56:00 CST 2019
package win.doyto.query.core;
import io.swagger.annotations.ApiModelProperty;
import win.doyto.query.validation.PageGroup;
import java.io.Serializable;
import javax.validation.constraints.Pattern;
import static java.lang.Math.max;
/**
* PageQuery
*
* @author f0rb
*/
public class PageQuery implements Serializable {
static final String RX_SORT = "(\\w+,(asc|desc);|field\\(\\w+(,[\\w\']+)+\\);)*\\w+,(asc|desc)";
private Integer pageNumber;
private Integer pageSize;
@ApiModelProperty("Sorting field, format: field1,desc;field2,asc")
@Pattern(regexp = RX_SORT, message = "Sorting field format error", groups = PageGroup.class)
private String sort;
public Integer getPageNumber() {
return getDefault(pageNumber, 0, pageSize == null);
}
public Integer getPageSize() {
return getDefault(pageSize, 10, pageNumber == null);
}
private Integer getDefault(Integer number, int defaultValue, boolean canBeNull) {
if (number == null) {
if (canBeNull) {
return null;
} else {
number = defaultValue;
}
}
return max(0, number);
}
public int getOffset() {
return needPaging() ? getPageSize() * getPageNumber() : 0;
}
public boolean needPaging() {
return getPageNumber() != null;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public PageQuery setPageNumber(final Integer pageNumber) {
this.pageNumber = pageNumber;
return this;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public PageQuery setPageSize(final Integer pageSize) {
this.pageSize = pageSize;
return this;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public String getSort() {
return this.sort;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public PageQuery setSort(final String sort) {
this.sort = sort;
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy