Skip to content

Instantly share code, notes, and snippets.

@vongosling
Created April 18, 2014 01:45
Show Gist options
  • Save vongosling/11020739 to your computer and use it in GitHub Desktop.
Save vongosling/11020739 to your computer and use it in GitHub Desktop.
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