mirror of https://github.com/apache/lucene.git
shallowMap() should behave like a map. testcase added
This commit is contained in:
parent
f65c114e1a
commit
84e01eb84b
|
@ -425,7 +425,12 @@ public class NamedList<T> implements Cloneable, Serializable, Iterable<Map.Entry
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T put(String key, T value) {
|
public T put(String key, T value) {
|
||||||
NamedList.this.add(key, value);
|
int idx = NamedList.this.indexOf(key, 0);
|
||||||
|
if (idx == -1) {
|
||||||
|
NamedList.this.add(key, value);
|
||||||
|
} else {
|
||||||
|
NamedList.this.setVal(idx, value);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,8 +441,10 @@ public class NamedList<T> implements Cloneable, Serializable, Iterable<Map.Entry
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putAll(Map m) {
|
public void putAll(Map m) {
|
||||||
NamedList.this.addAll(m);
|
for (Object o : m.entrySet()) {
|
||||||
|
Map.Entry e = (Entry) o;
|
||||||
|
put(e.getKey() == null ? null : e.getKey().toString(), (T) e.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.solr.common.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
|
@ -185,4 +186,21 @@ public class NamedListTest extends LuceneTestCase {
|
||||||
Object enltest4 = enl.findRecursive("key2");
|
Object enltest4 = enl.findRecursive("key2");
|
||||||
assertNull(enltest4);
|
assertNull(enltest4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testShallowMap() {
|
||||||
|
NamedList nl = new NamedList();
|
||||||
|
nl.add("key1", "Val1");
|
||||||
|
Map m = nl.asShallowMap();
|
||||||
|
m.put("key1", "Val1_");
|
||||||
|
assertEquals("Val1_", nl.get("key1"));
|
||||||
|
assertEquals("Val1_", m.get("key1"));
|
||||||
|
assertEquals(0, nl.indexOf("key1", 0));
|
||||||
|
m.putAll(Utils.makeMap("key1", "Val1__", "key2", "Val2"));
|
||||||
|
assertEquals("Val1__", nl.get("key1"));
|
||||||
|
assertEquals("Val1__", m.get("key1"));
|
||||||
|
assertEquals(0, nl.indexOf("key1", 0));
|
||||||
|
assertEquals("Val2", nl.get("key2"));
|
||||||
|
assertEquals("Val2", m.get("key2"));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue