You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/09/08 13:10:11 UTC

svn commit: r812461 - /incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java

Author: tvolkert
Date: Tue Sep  8 11:10:11 2009
New Revision: 812461

URL: http://svn.apache.org/viewvc?rev=812461&view=rev
Log:
PIVOT-282 :: Fix illegal item modification check in ArrayList.update()

Modified:
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java?rev=812461&r1=812460&r2=812461&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java Tue Sep  8 11:10:11 2009
@@ -259,9 +259,18 @@
         T previousItem = (T)items[index];
 
         if (previousItem != item) {
-            if (comparator != null
-                && binarySearch(this, item, comparator) != index) {
-                throw new IllegalArgumentException("Illegal item modification.");
+            if (comparator != null) {
+                // Ensure that the new item is greater or equal to its
+                // predecessor and less than or equal to its successor
+                T predecessorItem = (index > 0 ? (T)items[index - 1] : null);
+                T successorItem = (index < length - 1 ? (T)items[index + 1] : null);
+
+                if ((predecessorItem != null
+                    && comparator.compare(item, predecessorItem) == -1)
+                    || (successorItem != null
+                    && comparator.compare(item, successorItem) == 1)) {
+                    throw new IllegalArgumentException("Illegal item modification.");
+                }
             }
 
             items[index] = item;