From 50a43d611655aac99821f9670ecebaf969054018 Mon Sep 17 00:00:00 2001 From: fullwall Date: Tue, 10 Sep 2013 23:55:58 +0800 Subject: [PATCH] Reorder highest/lowest calculations - may fix issues with using remove() --- src/main/java/net/citizensnpcs/util/ByIdArray.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/citizensnpcs/util/ByIdArray.java b/src/main/java/net/citizensnpcs/util/ByIdArray.java index 4fef7bbdc..96554bde5 100644 --- a/src/main/java/net/citizensnpcs/util/ByIdArray.java +++ b/src/main/java/net/citizensnpcs/util/ByIdArray.java @@ -107,16 +107,15 @@ public class ByIdArray implements Iterable { public T remove(int index) { if (index > elementData.length || elementData[index] == null) return null; + @SuppressWarnings("unchecked") + T prev = (T) elementData[index]; + elementData[index] = null; + --size; ++modCount; if (index == highest) recalcHighest(); if (index == lowest) recalcLowest(); - @SuppressWarnings("unchecked") - T prev = (T) elementData[index]; - elementData[index] = null; - if (prev != null) - --size; return prev; } @@ -125,8 +124,9 @@ public class ByIdArray implements Iterable { } public void trimToSize() { - if (elementData.length > highest) + if (elementData.length > highest) { elementData = Arrays.copyOf(elementData, highest + 1); + } } private class Itr implements Iterator {