mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
处理 Partition<T> 的问题
This commit is contained in:
parent
a38e3e52af
commit
a425ac5fb3
@ -26,13 +26,14 @@ public class Partition<T> extends AbstractList<List<T>> {
|
|||||||
*/
|
*/
|
||||||
public Partition(List<T> list, int size) {
|
public Partition(List<T> list, int size) {
|
||||||
this.list = list;
|
this.list = list;
|
||||||
this.size = Math.min(size, list.size());
|
this.size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<T> get(int index) {
|
public List<T> get(int index) {
|
||||||
int start = index * size;
|
int listSize = list.size();
|
||||||
int end = Math.min(start + size, list.size());
|
int start = Math.min(index * size, listSize);
|
||||||
|
int end = Math.min(start + size, listSize);
|
||||||
return list.subList(start, end);
|
return list.subList(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,10 +42,7 @@ public class Partition<T> extends AbstractList<List<T>> {
|
|||||||
// 此处采用动态计算,以应对list变
|
// 此处采用动态计算,以应对list变
|
||||||
final int size = this.size;
|
final int size = this.size;
|
||||||
final int total = list.size();
|
final int total = list.size();
|
||||||
int length = total / size;
|
int length = (total + size - 1) / size;
|
||||||
if(total % size > 0){
|
|
||||||
length += 1;
|
|
||||||
}
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user