From 391b35d0f782156e76f10a9b3f64f115e9456952 Mon Sep 17 00:00:00 2001 From: fullwall Date: Tue, 24 Apr 2012 14:17:16 +0800 Subject: [PATCH] Minor changes --- .../java/net/citizensnpcs/util/ByIdArray.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/citizensnpcs/util/ByIdArray.java b/src/main/java/net/citizensnpcs/util/ByIdArray.java index cf1c00bec..9747d2bf0 100644 --- a/src/main/java/net/citizensnpcs/util/ByIdArray.java +++ b/src/main/java/net/citizensnpcs/util/ByIdArray.java @@ -132,26 +132,29 @@ public class ByIdArray implements Iterable { private int expected = ByIdArray.this.modCount; private int idx; { - if (lowest == Integer.MAX_VALUE || elementData[lowest] == null) { - recalcLowest(); - } - idx = lowest; - if (elementData[lowest] == null) { - Messaging.log("lowest is still null!"); + if (size > 0) { + if (highest == Integer.MIN_VALUE || elementData[highest] == null) + recalcHighest(); + if (lowest == Integer.MAX_VALUE || elementData[lowest] == null) + recalcLowest(); + idx = lowest; + if (elementData[lowest] == null) { + Messaging.log("lowest is still null!"); + } } } @Override public boolean hasNext() { - if (ByIdArray.this.modCount != expected) + if (modCount != expected) throw new ConcurrentModificationException(); - return highest + 1 > idx && size > 0; + return size > 0 && highest + 1 > idx; } @Override @SuppressWarnings("unchecked") public T next() { - if (ByIdArray.this.modCount != expected) + if (modCount != expected) throw new ConcurrentModificationException(); T next = (T) elementData[idx]; if (next == null || idx > highest) @@ -164,10 +167,10 @@ public class ByIdArray implements Iterable { @Override public void remove() { - if (ByIdArray.this.modCount != expected) + if (modCount != expected) throw new ConcurrentModificationException(); - ByIdArray.this.fastRemove(idx); - expected = ByIdArray.this.modCount; + fastRemove(idx); + expected = modCount; } }