generator.server.pagination.domain.main.AppPageable.mustache Maven / Gradle / Ivy
package {{packageName}}.shared.pagination.domain;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import {{packageName}}.shared.error.domain.Assert;
import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage;
public class {{baseName}}Pageable {
private final int page;
private final int pageSize;
private final int offset;
public {{baseName}}Pageable(int page, int pageSize) {
Assert.field("page", page).min(0);
Assert.field("pageSize", pageSize).min(1).max(100);
this.page = page;
this.pageSize = pageSize;
offset = page * pageSize;
}
public int page() {
return page;
}
public int pageSize() {
return pageSize;
}
public int offset() {
return offset;
}
@Override
@ExcludeFromGeneratedCodeCoverage
public int hashCode() {
return new HashCodeBuilder().append(page).append(pageSize).build();
}
@Override
@ExcludeFromGeneratedCodeCoverage
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
{{baseName}}Pageable other = ({{baseName}}Pageable) obj;
return new EqualsBuilder().append(page, other.page).append(pageSize, other.pageSize).build();
}
}