
org.springframework.data.domain.OffsetRequest Maven / Gradle / Ivy
package org.springframework.data.domain;
import org.springframework.data.domain.Sort.Direction;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.NumberPath;
public class OffsetRequest extends PageRequest {
private static final long serialVersionUID = -3577165005023019449L;
private int first;
private int last;
private int id;
private Direction direction;
private String pageParameterName;
private String sizeParameterName;
private String nextParameterName;
private String prevParameterName;
private OffsetRequest(int page, int size, Sort sort, Direction direction) {
super(page, size, sort);
this.direction = direction;
}
public OffsetRequest(int page, int size, Sort sort, String pageParameterName, String sizeParameterName, String nextParameterName, String prevParameterName) {
this(page, size, sort, pageParameterName, sizeParameterName, nextParameterName, prevParameterName, null, 0);
}
public OffsetRequest(int page, int size, Sort sort, String pageParameterName, String sizeParameterName, String nextParameterName, String prevParameterName, Direction direction, int id) {
super(page, size, sort);
this.pageParameterName = pageParameterName;
this.sizeParameterName = sizeParameterName;
this.nextParameterName = nextParameterName;
this.prevParameterName = prevParameterName;
this.direction = direction;
this.id = id;
}
public Predicate predicate(NumberPath> path) {
if (this.id == 0 || this.direction == null) {
return null;
}
switch (this.direction) {
case ASC:
return this.id < 0 ? path.lt(-this.id) : path.gt(this.id);
case DESC:
return this.id < 0 ? path.gt(-this.id) : path.lt(this.id);
default:
throw new UnsupportedOperationException();
}
}
@Override
public Pageable first() {
if (this.direction == null) {
return super.first();
}
switch (this.direction) {
case ASC:
return new OffsetRequest(this.first, getPageSize(), getSort(), this.direction);
case DESC:
return new OffsetRequest(this.first, getPageSize(), getSort(), this.direction);
default:
throw new UnsupportedOperationException();
}
}
@Override
public Pageable next() {
if (this.direction == null) {
return super.next();
}
switch (this.direction) {
case ASC:
return new OffsetRequest(this.last, getPageSize(), getSort(), this.direction);
case DESC:
return new OffsetRequest(this.last, getPageSize(), getSort(), this.direction);
default:
throw new UnsupportedOperationException();
}
}
public boolean hasDirection() {
return this.direction != null;
}
public int getId() {
return this.id < 0 ? -this.id : this.id;
}
public String getPageParameterName() {
return this.pageParameterName;
}
public String getSizeParameterName() {
return this.sizeParameterName;
}
public String getNextParameterName() {
return this.nextParameterName;
}
public String getPrevParameterName() {
return this.prevParameterName;
}
public void setFirst(int first) {
this.first = first;
}
public void setLast(int last) {
this.last = last;
}
public void setDirection(Direction direction) {
this.direction = direction;
}
@Override
public int hashCode() {
return super.hashCode();
}
@Override
public boolean equals(Object obj) {
return super.equals(obj);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy