You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/10/20 14:10:26 UTC

svn commit: r827045 - /incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/ListAdapter.java

Author: gbrown
Date: Tue Oct 20 12:10:26 2009
New Revision: 827045

URL: http://svn.apache.org/viewvc?rev=827045&view=rev
Log:
Ensure that ListAdapter fires update events even when the new item instance is the same as the previous instance.

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

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/ListAdapter.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/ListAdapter.java?rev=827045&r1=827044&r2=827045&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/ListAdapter.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/ListAdapter.java Tue Oct 20 12:10:26 2009
@@ -59,8 +59,7 @@
 
         if (comparator == null) {
             index = getLength();
-        }
-        else {
+        } else {
             // Perform a binary search to find the insertion point
             index = Collections.binarySearch(list, item, comparator);
             if (index < 0) {
@@ -90,41 +89,41 @@
         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 = null;
-            T successorItem = null;
+            T predecessor = null;
+            T successor = null;
 
             if (list instanceof RandomAccess) {
                 if (index > 0) {
-                    predecessorItem = list.get(index - 1);
+                    predecessor = list.get(index - 1);
                 }
 
                 if (index < getLength() - 1) {
-                    successorItem = list.get(index + 1);
+                    successor = list.get(index + 1);
                 }
             } else {
                 if (index == 0) {
                     // We're at the head of the list; successor is at index 1
-                    successorItem = list.get(1);
+                    successor = list.get(1);
                 } else {
                     ListIterator<T> listIterator = list.listIterator(index - 1);
 
                     // Get the predecessor
-                    predecessorItem = listIterator.next();
+                    predecessor = listIterator.next();
 
                     // Advance to the item being updated
                     listIterator.next();
 
                     // Get the successor if one exists
                     if (listIterator.hasNext()) {
-                        successorItem = listIterator.next();
+                        successor = listIterator.next();
                     }
                 }
             }
 
-            if ((predecessorItem != null
-                && comparator.compare(item, predecessorItem) == -1)
-                || (successorItem != null
-                && comparator.compare(item, successorItem) == 1)) {
+            if ((predecessor != null
+                    && comparator.compare(item, predecessor) == -1)
+                || (successor != null
+                        && comparator.compare(item, successor) == 1)) {
                 throw new IllegalArgumentException("Illegal item modification.");
             }
         }
@@ -136,8 +135,9 @@
 
             if (previousItem != item) {
                 list.set(index, item);
-                listListeners.itemUpdated(this, index, previousItem);
             }
+
+            listListeners.itemUpdated(this, index, previousItem);
         } else {
             ListIterator<T> listIterator = list.listIterator(index);
             previousItem = listIterator.next();
@@ -148,9 +148,9 @@
                 } catch (UnsupportedOperationException exception) {
                     list.set(index, item);
                 }
-
-                listListeners.itemUpdated(this, index, previousItem);
             }
+
+            listListeners.itemUpdated(this, index, previousItem);
         }
 
         return previousItem;