~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/solrj/src/java/org/apache/solr/common/params/MultiMapSolrParams.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
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
8
 
 *
9
 
 *     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
 
 */
17
 
 
18
 
package org.apache.solr.common.params;
19
 
 
20
 
import org.apache.solr.common.util.StrUtils;
21
 
 
22
 
import java.util.Iterator;
23
 
import java.util.Map;
24
 
import java.io.IOException;
25
 
 
26
 
/**
27
 
 * @version $Id$
28
 
 */
29
 
public class MultiMapSolrParams extends SolrParams {
30
 
  protected final Map<String,String[]> map;
31
 
 
32
 
  public static void addParam(String name, String val, Map<String,String[]> map) {
33
 
      String[] arr = map.get(name);
34
 
      if (arr ==null) {
35
 
        arr =new String[]{val};
36
 
      } else {
37
 
        String[] newarr = new String[arr.length+1];
38
 
        System.arraycopy(arr,0,newarr,0,arr.length);
39
 
        newarr[arr.length]=val;
40
 
        arr =newarr;
41
 
      }
42
 
      map.put(name, arr);
43
 
  }
44
 
 
45
 
  public MultiMapSolrParams(Map<String,String[]> map) {
46
 
    this.map = map;
47
 
  }
48
 
 
49
 
  @Override
50
 
  public String get(String name) {
51
 
    String[] arr = map.get(name);
52
 
    return arr==null ? null : arr[0];
53
 
  }
54
 
 
55
 
  @Override
56
 
  public String[] getParams(String name) {
57
 
    return map.get(name);
58
 
  }
59
 
 
60
 
  @Override
61
 
  public Iterator<String> getParameterNamesIterator() {
62
 
    return map.keySet().iterator();
63
 
  }
64
 
 
65
 
  public Map<String,String[]> getMap() { return map; }
66
 
 
67
 
  @Override
68
 
  public String toString() {
69
 
    StringBuilder sb = new StringBuilder(128);
70
 
    try {
71
 
      boolean first=true;
72
 
 
73
 
      for (Map.Entry<String,String[]> entry : map.entrySet()) {
74
 
        String key = entry.getKey();
75
 
        String[] valarr = entry.getValue();
76
 
 
77
 
        for (String val : valarr) {
78
 
          if (!first) sb.append('&');
79
 
          first=false;
80
 
          sb.append(key);
81
 
          sb.append('=');
82
 
          StrUtils.partialURLEncodeVal(sb, val==null ? "" : val);
83
 
        }
84
 
      }
85
 
    }
86
 
    catch (IOException e) {throw new RuntimeException(e);}  // can't happen
87
 
 
88
 
    return sb.toString();
89
 
  }
90
 
 
91
 
 
92
 
}