Merge pull request #2441 from fanthos/patch-1

处理 Partition<T> 的问题
This commit is contained in:
Golden Looly 2022-07-16 11:43:36 +08:00 committed by GitHub
commit 22366f38f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,13 +26,14 @@ public class Partition<T> extends AbstractList<List<T>> {
*/
public Partition(List<T> list, int size) {
this.list = list;
this.size = Math.min(size, list.size());
this.size = size;
}
@Override
public List<T> get(int index) {
int start = index * size;
int end = Math.min(start + size, list.size());
int listSize = list.size();
int start = Math.min(index * size, listSize);
int end = Math.min(start + size, listSize);
return list.subList(start, end);
}
@ -41,10 +42,7 @@ public class Partition<T> extends AbstractList<List<T>> {
// 此处采用动态计算以应对list变
final int size = this.size;
final int total = list.size();
int length = total / size;
if(total % size > 0){
length += 1;
}
int length = (total + size - 1) / size;
return length;
}