3
0
This commit is contained in:
Prototik
2015-10-23 01:33:13 +07:00
parent 4cfa07d415
commit d3c359b26d
2 changed files with 77 additions and 3 deletions

View File

@ -4,6 +4,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import cpw.mods.fml.common.FMLLog;
public class LinkedHelper<T> {
private final Iterable<T> mIterable;
private volatile Iterator<T> mIndexIterator;
@ -21,10 +23,21 @@ public class LinkedHelper<T> {
}
if (mIndex == index) return mIndexValue;
T value = null;
while (mIndex < index) {
while (mIndex < index && mIndexIterator.hasNext()) {
value = mIndexIterator.next();
mIndex++;
}
if (mIndex < index) {
mIndexIterator = mIterable.iterator();
mIndex = -1;
while (mIndex < index && mIndexIterator.hasNext()) {
value = mIndexIterator.next();
mIndex++;
}
}
if (mIndex < index) {
FMLLog.bigWarning("LinkedHelper desync, report this to KCauldron tracker!");
}
return mIndexValue = value;
}