COLLECTIONS-228 - MultiValueMap put and putAll do not return the correct values
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_jdk5_branch@468685 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c440b250f2
commit
c5a502a084
|
@ -206,12 +206,12 @@ public class MultiValueMap extends AbstractMapDecorator implements MultiMap {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
Collection coll = getCollection(key);
|
Collection coll = getCollection(key);
|
||||||
if (coll == null) {
|
if (coll == null) {
|
||||||
coll = createCollection(1);
|
coll = createCollection(1); // might produce a non-empty collection
|
||||||
result = coll.add(value);
|
coll.add(value);
|
||||||
if (coll.size() > 0) {
|
if (coll.size() > 0) {
|
||||||
// only add if non-zero size to maintain class state
|
// only add if non-zero size to maintain class state
|
||||||
getMap().put(key, coll);
|
getMap().put(key, coll);
|
||||||
result = false;
|
result = true; // map definitely changed
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = coll.add(value);
|
result = coll.add(value);
|
||||||
|
@ -308,19 +308,20 @@ public class MultiValueMap extends AbstractMapDecorator implements MultiMap {
|
||||||
if (values == null || values.size() == 0) {
|
if (values == null || values.size() == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
boolean result = false;
|
||||||
Collection coll = getCollection(key);
|
Collection coll = getCollection(key);
|
||||||
if (coll == null) {
|
if (coll == null) {
|
||||||
coll = createCollection(values.size());
|
coll = createCollection(values.size()); // might produce a non-empty collection
|
||||||
boolean result = coll.addAll(values);
|
coll.addAll(values);
|
||||||
if (coll.size() > 0) {
|
if (coll.size() > 0) {
|
||||||
// only add if non-zero size to maintain class state
|
// only add if non-zero size to maintain class state
|
||||||
getMap().put(key, coll);
|
getMap().put(key, coll);
|
||||||
result = false;
|
result = true; // map definitely changed
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = coll.addAll(values);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} else {
|
|
||||||
return coll.addAll(values);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,7 +31,6 @@ import junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.apache.commons.collections.IteratorUtils;
|
import org.apache.commons.collections.IteratorUtils;
|
||||||
import org.apache.commons.collections.MultiMap;
|
import org.apache.commons.collections.MultiMap;
|
||||||
import org.apache.commons.collections.TestMultiHashMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestMultiValueMap.
|
* TestMultiValueMap.
|
||||||
|
@ -47,11 +46,11 @@ public class TestMultiValueMap extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
return new TestSuite(TestMultiHashMap.class);
|
return new TestSuite(TestMultiValueMap.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
String[] testCaseName = { TestMultiHashMap.class.getName()};
|
String[] testCaseName = { TestMultiValueMap.class.getName()};
|
||||||
junit.textui.TestRunner.main(testCaseName);
|
junit.textui.TestRunner.main(testCaseName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,9 +201,9 @@ public class TestMultiValueMap extends TestCase {
|
||||||
map.put("B", "BC");
|
map.put("B", "BC");
|
||||||
assertEquals(2, map.size());
|
assertEquals(2, map.size());
|
||||||
map.remove("A");
|
map.remove("A");
|
||||||
assertEquals(2, map.size());
|
assertEquals(1, map.size());
|
||||||
map.remove("B", "BC");
|
map.remove("B", "BC");
|
||||||
assertEquals(2, map.size());
|
assertEquals(1, map.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSize_Key() {
|
public void testSize_Key() {
|
||||||
|
@ -250,6 +249,25 @@ public class TestMultiValueMap extends TestCase {
|
||||||
assertEquals(false, map.containsValue("A", "AB"));
|
assertEquals(false, map.containsValue("A", "AB"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testPutWithList() {
|
||||||
|
MultiValueMap test = MultiValueMap.decorate(new HashMap(), ArrayList.class);
|
||||||
|
assertEquals("a", test.put("A", "a"));
|
||||||
|
assertEquals("b", test.put("A", "b"));
|
||||||
|
assertEquals(1, test.size());
|
||||||
|
assertEquals(2, test.size("A"));
|
||||||
|
assertEquals(2, test.totalSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPutWithSet() {
|
||||||
|
MultiValueMap test = MultiValueMap.decorate(new HashMap(), HashSet.class);
|
||||||
|
assertEquals("a", test.put("A", "a"));
|
||||||
|
assertEquals("b", test.put("A", "b"));
|
||||||
|
assertEquals(null, test.put("A", "a"));
|
||||||
|
assertEquals(1, test.size());
|
||||||
|
assertEquals(2, test.size("A"));
|
||||||
|
assertEquals(2, test.totalSize());
|
||||||
|
}
|
||||||
|
|
||||||
public void testPutAll_Map1() {
|
public void testPutAll_Map1() {
|
||||||
MultiMap original = new MultiValueMap();
|
MultiMap original = new MultiValueMap();
|
||||||
original.put("key", "object1");
|
original.put("key", "object1");
|
||||||
|
|
Loading…
Reference in New Issue