2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.solr.common.params;
20
import org.apache.solr.common.util.StrUtils;
22
import java.util.Iterator;
24
import java.io.IOException;
29
public class MultiMapSolrParams extends SolrParams {
30
protected final Map<String,String[]> map;
32
public static void addParam(String name, String val, Map<String,String[]> map) {
33
String[] arr = map.get(name);
35
arr =new String[]{val};
37
String[] newarr = new String[arr.length+1];
38
System.arraycopy(arr,0,newarr,0,arr.length);
39
newarr[arr.length]=val;
45
public MultiMapSolrParams(Map<String,String[]> map) {
50
public String get(String name) {
51
String[] arr = map.get(name);
52
return arr==null ? null : arr[0];
56
public String[] getParams(String name) {
61
public Iterator<String> getParameterNamesIterator() {
62
return map.keySet().iterator();
65
public Map<String,String[]> getMap() { return map; }
68
public String toString() {
69
StringBuilder sb = new StringBuilder(128);
73
for (Map.Entry<String,String[]> entry : map.entrySet()) {
74
String key = entry.getKey();
75
String[] valarr = entry.getValue();
77
for (String val : valarr) {
78
if (!first) sb.append('&');
82
StrUtils.partialURLEncodeVal(sb, val==null ? "" : val);
86
catch (IOException e) {throw new RuntimeException(e);} // can't happen