mirror of https://github.com/apache/lucene.git
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.
This commit is contained in:
parent
eb587772dd
commit
583fec1a58
|
@ -116,6 +116,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.
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue