You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2016/09/16 11:39:04 UTC

lucene-solr:master: shallowMap() should behave like a map. testcase added

Repository: lucene-solr
Updated Branches:
  refs/heads/master f65c114e1 -> 84e01eb84


shallowMap() should behave like a map. testcase added


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/84e01eb8
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/84e01eb8
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/84e01eb8

Branch: refs/heads/master
Commit: 84e01eb84becffc758d59374d0ed8f7bc7e5db58
Parents: f65c114
Author: Noble Paul <no...@apache.org>
Authored: Fri Sep 16 17:08:55 2016 +0530
Committer: Noble Paul <no...@apache.org>
Committed: Fri Sep 16 17:08:55 2016 +0530

----------------------------------------------------------------------
 .../org/apache/solr/common/util/NamedList.java    | 13 ++++++++++---
 .../apache/solr/common/util/NamedListTest.java    | 18 ++++++++++++++++++
 2 files changed, 28 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/84e01eb8/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java b/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java
index dd5afe7..858fec9 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java
@@ -425,7 +425,12 @@ public class NamedList<T> implements Cloneable, Serializable, Iterable<Map.Entry
 
       @Override
       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;
       }
 
@@ -436,8 +441,10 @@ public class NamedList<T> implements Cloneable, Serializable, Iterable<Map.Entry
 
       @Override
       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

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/84e01eb8/solr/solrj/src/test/org/apache/solr/common/util/NamedListTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/common/util/NamedListTest.java b/solr/solrj/src/test/org/apache/solr/common/util/NamedListTest.java
index 2625e7d..8605cd9 100644
--- a/solr/solrj/src/test/org/apache/solr/common/util/NamedListTest.java
+++ b/solr/solrj/src/test/org/apache/solr/common/util/NamedListTest.java
@@ -18,6 +18,7 @@ package org.apache.solr.common.util;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.solr.common.SolrException;
@@ -185,4 +186,21 @@ public class NamedListTest extends LuceneTestCase {
     Object enltest4 = enl.findRecursive("key2");
     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"));
+
+  }
 }