groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwagenleit...@apache.org
Subject [2/2] groovy git commit: GROOVY-7816 - ObservableList addAll method property change event index off by one (closes #313)
Date Sun, 17 Apr 2016 18:46:30 GMT
GROOVY-7816 - ObservableList addAll method property change event index off by one (closes #313)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/d7cf6be5
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d7cf6be5
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d7cf6be5

Branch: refs/heads/GROOVY_2_4_X
Commit: d7cf6be5098e2aad9c3e78ce541316444adff968
Parents: c64d3ee
Author: John Wagenleitner <jwagenleitner@apache.org>
Authored: Sun Apr 17 10:38:31 2016 -0700
Committer: John Wagenleitner <jwagenleitner@apache.org>
Committed: Sun Apr 17 11:44:56 2016 -0700

----------------------------------------------------------------------
 src/main/groovy/util/ObservableList.java       | 25 +--------------------
 src/test/groovy/util/ObservableListTest.groovy | 10 +++++----
 2 files changed, 7 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/d7cf6be5/src/main/groovy/util/ObservableList.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/util/ObservableList.java b/src/main/groovy/util/ObservableList.java
index 981735d..a0e5476 100644
--- a/src/main/groovy/util/ObservableList.java
+++ b/src/main/groovy/util/ObservableList.java
@@ -168,30 +168,7 @@ public class ObservableList implements List {
     }
 
     public boolean addAll(Collection c) {
-        int oldSize = size();
-        int index = size() - 1;
-        index = index < 0 ? 0 : index;
-
-        boolean success = delegate.addAll(c);
-        if (success && c != null) {
-            List values = new ArrayList();
-            for (Object element : c) {
-                if (test != null) {
-                    Object result = test.call(element);
-                    if (result != null && result instanceof Boolean && (Boolean)
result) {
-                        values.add(element);
-                    }
-                } else {
-                    values.add(element);
-                }
-            }
-            if (!values.isEmpty()) {
-                fireMultiElementAddedEvent(index, values);
-                fireSizeChangedEvent(oldSize, size());
-            }
-        }
-
-        return success;
+        return addAll(size(), c);
     }
 
     public boolean addAll(int index, Collection c) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/d7cf6be5/src/test/groovy/util/ObservableListTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/util/ObservableListTest.groovy b/src/test/groovy/util/ObservableListTest.groovy
index 993ef08..4e76604 100644
--- a/src/test/groovy/util/ObservableListTest.groovy
+++ b/src/test/groovy/util/ObservableListTest.groovy
@@ -158,15 +158,16 @@ class ObservableListTest extends GroovyTestCase {
         list.addPropertyChangeListener(ObservableList.SIZE_PROPERTY, sizeListener)
 
         def value1 = 'value1'
-        def value2 = 'value2'
         list << value1
 
         assertNotNull(sizeListener.event)
         assertEquals(list, contentListener.event.source)
         assertEquals(0i, sizeListener.event.oldValue)
         assertEquals(1i, sizeListener.event.newValue)
+        assertEquals(0i, contentListener.event.index)
 
-        list.addAll([value1, value2])
+        def value2 = 'value2'
+        list.addAll([value2, value1])
 
         assertNotNull(contentListener.event)
         assertTrue(contentListener.event instanceof ObservableList.MultiElementAddedEvent)
@@ -174,12 +175,13 @@ class ObservableListTest extends GroovyTestCase {
         def values = contentListener.event.values
         assertNotNull(values)
         assertEquals(2, values.size())
-        assertEquals(value1, values[0])
-        assertEquals(value2, values[1])
+        assertEquals(value2, values[0])
+        assertEquals(value1, values[1])
         assertNotNull(sizeListener.event)
         assertEquals(list, contentListener.event.source)
         assertEquals(1i, sizeListener.event.oldValue)
         assertEquals(3i, sizeListener.event.newValue)
+        assertEquals(1i, contentListener.event.index)
     }
 
     void testFireEvent_removeAll() {


Mime
View raw message