You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ko...@apache.org on 2017/03/23 06:45:11 UTC

lucene-solr:branch_6x: SOLR-9184: Add a static convenience method ModifiableSolrParams#of(SolrParams) which returns the same instance if it already is modifiable, otherwise creates a new ModifiableSolrParams instance.

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 95be4eba2 -> bcd452c6a


SOLR-9184: Add a static convenience method ModifiableSolrParams#of(SolrParams) which returns the same instance if it already is modifiable, otherwise creates a new ModifiableSolrParams instance.


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

Branch: refs/heads/branch_6x
Commit: bcd452c6a1026bcec814e355b8366c9b4ece49e0
Parents: 95be4eb
Author: koji <ko...@apache.org>
Authored: Thu Mar 23 15:44:56 2017 +0900
Committer: koji <ko...@apache.org>
Committed: Thu Mar 23 15:44:56 2017 +0900

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  7 ++++++
 .../common/params/ModifiableSolrParams.java     | 13 ++++++++++
 .../common/params/ModifiableSolrParamsTest.java | 26 ++++++++++++++++++++
 3 files changed, 46 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/bcd452c6/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 077805e..e9396c4 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -41,6 +41,13 @@ New Features
 
 * SOLR-9994: Add support for CollapseQParser with PointFields. (Varun Thacker, Cao Manh Dat)
 
+Optimizations
+----------------------
+
+* SOLR-9184: Add a static convenience method ModifiableSolrParams#of(SolrParams) which returns the same
+  instance if it already is modifiable, otherwise creates a new ModifiableSolrParams instance.
+  (J�rg Rathlev via Koji)
+
 ==================  6.5.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/bcd452c6/solr/solrj/src/java/org/apache/solr/common/params/ModifiableSolrParams.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/params/ModifiableSolrParams.java b/solr/solrj/src/java/org/apache/solr/common/params/ModifiableSolrParams.java
index e3cb499..da6bcf1 100644
--- a/solr/solrj/src/java/org/apache/solr/common/params/ModifiableSolrParams.java
+++ b/solr/solrj/src/java/org/apache/solr/common/params/ModifiableSolrParams.java
@@ -54,6 +54,19 @@ public class ModifiableSolrParams extends SolrParams
     }
   }
 
+  /**
+   * If the input params are of type MofifiableSolrParams, returns the input, otherwise, constructs a new
+   * ModifiableSolrParams, copying values from the given params. If params is null, returns an empty
+   * ModifiableSolrParams instance.
+   */
+  public static ModifiableSolrParams of(SolrParams params)
+  {
+    if (params instanceof ModifiableSolrParams) {
+      return (ModifiableSolrParams) params;
+    }
+    return new ModifiableSolrParams(params);
+  }
+
   public int size() {
     return vals == null ? 0 : vals.size();
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/bcd452c6/solr/solrj/src/test/org/apache/solr/common/params/ModifiableSolrParamsTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/common/params/ModifiableSolrParamsTest.java b/solr/solrj/src/test/org/apache/solr/common/params/ModifiableSolrParamsTest.java
index b65b607..c315b08 100644
--- a/solr/solrj/src/test/org/apache/solr/common/params/ModifiableSolrParamsTest.java
+++ b/solr/solrj/src/test/org/apache/solr/common/params/ModifiableSolrParamsTest.java
@@ -18,6 +18,9 @@ package org.apache.solr.common.params;
 
 import org.apache.lucene.util.LuceneTestCase;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * Unit Test Case for {@link org.apache.solr.common.params.ModifiableSolrParams
  * ModifiableSolrParams}
@@ -39,6 +42,29 @@ public class ModifiableSolrParamsTest extends LuceneTestCase {
     super.tearDown();
   }
 
+  public void testOf() throws Exception
+  {
+    String key = "key";
+    String value = "value";
+
+    // input is not of type ModifiableSolrParams
+    Map<String, String> values = new HashMap<>();
+    values.put(key, value);
+    SolrParams mapParams = new MapSolrParams(values);
+    ModifiableSolrParams result = ModifiableSolrParams.of(mapParams);
+    assertNotSame(mapParams, result);
+    assertEquals(value, result.get(key));
+
+    // input is of type ModifiableSolrParams
+    modifiable.add(key, value);
+    result = ModifiableSolrParams.of(modifiable);
+    assertSame(result, modifiable);
+
+    // input is null
+    result = ModifiableSolrParams.of(null);
+    assertNotNull(result);
+    assertEquals(0, result.size());
+  }
 
   public void testAdd()
   {