com.github.paganini2008.devtools.beans.streaming.MemoryResultSetSlice Maven / Gradle / Ivy
package com.github.paganini2008.devtools.beans.streaming;
import java.util.ArrayList;
import java.util.List;
import com.github.paganini2008.devtools.collection.ListUtils;
import com.github.paganini2008.devtools.jdbc.ResultSetSlice;
/**
*
* MemoryResultSetSlice
*
* @author Fred Feng
*
* @version 1.0
*/
public class MemoryResultSetSlice implements ResultSetSlice {
private final List content;
private final Transformer transformer;
MemoryResultSetSlice(List content, Transformer transformer) {
this.content = content;
this.transformer = transformer;
}
public List list(int maxResults, int firstResult) {
List results = new ArrayList();
List subList = ListUtils.slice(content, maxResults, firstResult);
for (E element : subList) {
T data = transformer.transfer(element);
results.add(data);
}
return results;
}
public int totalCount() {
return content.size();
}
}