01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
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.
16: */package org.apache.solr.request;
17:
18: import org.apache.solr.util.StrUtils;
19:
20: import java.util.Iterator;
21: import java.util.Map;
22: import java.io.IOException;
23:
24: /**
25: * @author yonik
26: * @version $Id$
27: */
28: public class MapSolrParams extends SolrParams {
29: protected final Map<String, String> map;
30:
31: public MapSolrParams(Map<String, String> map) {
32: this .map = map;
33: }
34:
35: public String get(String name) {
36: return map.get(name);
37: }
38:
39: public String[] getParams(String name) {
40: String val = map.get(name);
41: return val == null ? null : new String[] { val };
42: }
43:
44: public Iterator<String> getParameterNamesIterator() {
45: return map.keySet().iterator();
46: }
47:
48: public Map<String, String> getMap() {
49: return map;
50: }
51:
52: public String toString() {
53: StringBuilder sb = new StringBuilder(128);
54: try {
55: boolean first = true;
56:
57: for (Map.Entry<String, String> entry : map.entrySet()) {
58: String key = entry.getKey();
59: String val = entry.getValue();
60:
61: if (!first)
62: sb.append('&');
63: first = false;
64: sb.append(key);
65: sb.append('=');
66: StrUtils
67: .partialURLEncodeVal(sb, val == null ? "" : val);
68: }
69: } catch (IOException e) {
70: throw new RuntimeException(e);
71: } // can't happen
72:
73: return sb.toString();
74: }
75: }
|