Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Feeds system Result List based cursor theory
/**
* Result List based cursor theory
*
* @author vongosling
* @param <T>
*/
public class ResultCursorList<T> extends BaseDo {
private static final long serialVersionUID = -6593448580923210640L;
/**
* Result list
*/
private List<T> values;
/**
* Total result
*/
private Long totalCount;
/**
* For forwarding query,it can be timestamp or offset,when
* timestamp,previousCursor must be less than or equals nextCursor
*/
private Long previousCursor;
/**
* For backwarding query
*/
private Long nextCursor;
/**
* Init case
*
* @param clasz
* @return
*/
public static <T> ResultCursorList<T> build(Class<T> clazz) {
return new ResultCursorList<T>().setValues(new ArrayList<T>()).setTotalCount(0l)
.setPreviousCursor(0l).setNextCursor(0l);
}
/**
* Common case
*
* @param clasz
* @param values
* @param totalCount
* @param previousCursor
* @param nextCursor
* @return
*/
public static <T> ResultCursorList<T> build(Class<T> clazz, List<T> values, Long totalCount,
Long previousCursor, Long nextCursor) {
if (values == null || values.isEmpty()) {
return build(clazz);
}
return new ResultCursorList<T>().setValues(values).setTotalCount(totalCount)
.setPreviousCursor(previousCursor).setNextCursor(nextCursor);
}
public List<T> getValues() {
return values;
}
public ResultCursorList<T> setValues(List<T> values) {
this.values = values;
return this;
}
public Long getTotalCount() {
return totalCount;
}
public ResultCursorList<T> setTotalCount(Long totalCount) {
this.totalCount = totalCount;
return this;
}
public Long getPreviousCursor() {
return previousCursor;
}
public ResultCursorList<T> setPreviousCursor(Long previousCursor) {
this.previousCursor = previousCursor;
return this;
}
public Long getNextCursor() {
return nextCursor;
}
public ResultCursorList<T> setNextCursor(Long nextCursor) {
this.nextCursor = nextCursor;
return this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.