Extra validation code in Itr

This commit is contained in:
fullwall 2012-04-24 14:01:52 +08:00
parent a975b9ebf5
commit 8c28909411

View File

@ -92,11 +92,13 @@ public class ByIdArray<T> implements Iterable<T> {
} }
private void recalcHighest() { private void recalcHighest() {
highest = elementData.length - 1;
while (highest != 0 && elementData[highest--] == null) while (highest != 0 && elementData[highest--] == null)
; ;
} }
private void recalcLowest() { private void recalcLowest() {
lowest = 0;
while (elementData.length > lowest && highest > lowest && elementData[lowest++] == null) while (elementData.length > lowest && highest > lowest && elementData[lowest++] == null)
; ;
} }
@ -128,7 +130,16 @@ public class ByIdArray<T> implements Iterable<T> {
private class Itr implements Iterator<T> { private class Itr implements Iterator<T> {
private int expected = ByIdArray.this.modCount; private int expected = ByIdArray.this.modCount;
private int idx = lowest; private int idx;
{
if (lowest == Integer.MIN_VALUE || elementData[lowest] == null) {
recalcLowest();
}
idx = lowest;
if (elementData[lowest] == null) {
Messaging.log("lowest is still null!");
}
}
@Override @Override
public boolean hasNext() { public boolean hasNext() {