Fixes issue #2054; AbstractCollection.removeAll() produced incorrect results when the collection contained duplicates.
Patch by: me (fix), sgross (test case)
Review by: spoon (desk)
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2537 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/super/com/google/gwt/emul/java/util/AbstractCollection.java b/user/super/com/google/gwt/emul/java/util/AbstractCollection.java
index 25378ee..d4aa64d 100644
--- a/user/super/com/google/gwt/emul/java/util/AbstractCollection.java
+++ b/user/super/com/google/gwt/emul/java/util/AbstractCollection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2007 Google Inc.
+ * Copyright 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
@@ -85,10 +85,11 @@
}
public boolean removeAll(Collection<?> c) {
- Iterator<?> iter = c.iterator();
+ Iterator<?> iter = iterator();
boolean changed = false;
while (iter.hasNext()) {
- if (remove(iter.next())) {
+ if (c.contains(iter.next())) {
+ iter.remove();
changed = true;
}
}
diff --git a/user/test/com/google/gwt/emultest/java/util/ListTestBase.java b/user/test/com/google/gwt/emultest/java/util/ListTestBase.java
index 756ca47..524fca7 100644
--- a/user/test/com/google/gwt/emultest/java/util/ListTestBase.java
+++ b/user/test/com/google/gwt/emultest/java/util/ListTestBase.java
@@ -17,6 +17,7 @@
import org.apache.commons.collections.TestArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.ListIterator;
@@ -110,7 +111,17 @@
public void testListIteratorRemove() {
// TODO(jat): implement
}
-
+
+ public void testRemoveAllDuplicates() {
+ Collection c = makeCollection();
+ c.add("a");
+ c.add("a");
+ Collection d = makeCollection();
+ d.add("a");
+ assertTrue(c.removeAll(d));
+ assertEquals(0, c.size());
+ }
+
public void testToArray() {
List l = makeEmptyList();
for (int i = 0; i < 10; i++) {