-
-
Save xexes/6068743 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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