From 62045c9cc0416557e6b57b6f4101b98a0da02dde Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 21 Oct 2021 23:36:28 +0800 Subject: Fix most of the issues in #643 --- .../me/shedaniel/rei/api/common/util/CollectionUtils.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'api/src') diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java index 97934437d..09511ac6f 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java @@ -306,7 +306,20 @@ public class CollectionUtils { @Override public List next() { int cursor = i++ * size; - return list.subList(cursor, cursor + Math.min(list.size() - cursor, size)); + int realSize = Math.min(list.size() - cursor, size); + return new AbstractList() { + @Override + public T get(int index) { + if (index < 0 || index >= realSize) + throw new IndexOutOfBoundsException(String.format("Index %s out of bounds for length %s", index, realSize)); + return list.get(cursor + index); + } + + @Override + public int size() { + return realSize; + } + }; } }; } -- cgit