##### Coverage Report - org.apache.commons.fileupload.util.FileItemHeadersImpl

Classes in this File | Line Coverage | Branch Coverage | Complexity
FileItemHeadersImpl |
100% | 20/20
100% | 6/6
| 2.0;2

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 |  |
     package org.apache.commons.fileupload.util;
18 |  |
19 |  |
     import java.io.Serializable;
20 |  |
     import java.util.ArrayList;
21 |  |
     import java.util.Collections;
22 |  |
     import java.util.Iterator;
23 |  |
     import java.util.LinkedHashMap;
24 |  |
     import java.util.List;
25 |  |
     import java.util.Locale;
26 |  |
     import java.util.Map;
27 |  |
28 |  |
     import org.apache.commons.fileupload.FileItemHeaders;
29 |  |
30 |  |
     /**
31 |  |
      * Default implementation of the {@link FileItemHeaders} interface.
32 |  |
      *
33 |  |
      * @since 1.2.1
34 |  |
      */
35 | 3196 |
     public class FileItemHeadersImpl implements FileItemHeaders, Serializable {
36 |  |
37 |  |
         /**
38 |  |
          * Serial version UID, being used, if serialized.
39 |  |
          */
40 |  |
         private static final long serialVersionUID = -4455695752627032559L;
41 |  |
42 |  |
         /**
43 |  |
          * Map of <code>String</code> keys to a <code>List</code> of
44 |  |
          * <code>String</code> instances.
45 |  |
          */
46 | 3196 |
         private final Map<String, List<String>> headerNameToValueListMap = new LinkedHashMap<String, List<String>>();
47 |  |
48 |  |
         /**
49 |  |
          * {@inheritDoc}
50 |  |
          */
51 |  |
         @Override
52 |  |
         public String getHeader(String name) {
53 | 15988 |
             String nameLower = name.toLowerCase(Locale.ENGLISH);
54 | 15988 |
             List<String> headerValueList = headerNameToValueListMap.get(nameLower);
55 | 15988 |
             if (null == headerValueList) {
56 | 9539 |
                 return null;
57 |  |
             }
58 | 6449 |
             return headerValueList.get(0);
59 |  |
         }
60 |  |
61 |  |
         /**
62 |  |
          * {@inheritDoc}
63 |  |
          */
64 |  |
         @Override
65 |  |
         public Iterator<String> getHeaderNames() {
66 | 1 |
             return headerNameToValueListMap.keySet().iterator();
67 |  |
         }
68 |  |
69 |  |
         /**
70 |  |
          * {@inheritDoc}
71 |  |
          */
72 |  |
         @Override
73 |  |
         public Iterator<String> getHeaders(String name) {
74 | 4 |
             String nameLower = name.toLowerCase(Locale.ENGLISH);
75 | 4 |
             List<String> headerValueList = headerNameToValueListMap.get(nameLower);
76 | 4 |
             if (null == headerValueList) {
77 | 1 |
                 headerValueList = Collections.emptyList();
78 |  |
             }
79 | 4 |
             return headerValueList.iterator();
80 |  |
         }
81 |  |
82 |  |
         /**
83 |  |
          * Method to add header values to this instance.
84 |  |
          *
85 |  |
          * @param name name of this header
86 |  |
          * @param value value of this header
87 |  |
          */
88 |  |
         public synchronized void addHeader(String name, String value) {
89 | 3247 |
             String nameLower = name.toLowerCase(Locale.ENGLISH);
90 | 3247 |
             List<String> headerValueList = headerNameToValueListMap.get(nameLower);
91 | 3247 |
             if (null == headerValueList) {
92 | 3244 |
                 headerValueList = new ArrayList<String>();
93 | 3244 |
                 headerNameToValueListMap.put(nameLower, headerValueList);
94 |  |
             }
95 | 3247 |
             headerValueList.add(value);
96 | 3247 |
         }
97 |  |
98 |  |
     }