Skip to content

Instantly share code, notes, and snippets.

@xexes
Forked from anonymous/EnumerationIndoUtil
Created July 24, 2013 07:50
Show Gist options
  • Save xexes/6068743 to your computer and use it in GitHub Desktop.
Save xexes/6068743 to your computer and use it in GitHub Desktop.
public class EnumerationIndoUtil {
public static <T1> Enumeration<List<T1>> createPartitionedEnumeration(final List<T1> originalList, final int blockSize) {
class PartitionedEnum implements Enumeration<List<T1>> {
int lastIndex = 0;
public boolean hasMoreElements() {
return this.lastIndex < originalList.size();
}
public List<T1> nextElement() {
int beginIndex = this.lastIndex;
int endIndex = 0;
if (this.lastIndex + blockSize > originalList.size()) {
endIndex = originalList.size();
} else {
endIndex = this.lastIndex + blockSize;
}
this.lastIndex = endIndex;
return originalList.subList(beginIndex, endIndex);
}
}
return new PartitionedEnum();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment