
leap.lang.http.QueryStringMap Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package leap.lang.http;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class QueryStringMap extends LinkedHashMap> implements QueryString {
private static final long serialVersionUID = 2401756504509556691L;
private Map map;
public QueryStringMap() {
super();
}
public QueryStringMap(int initialCapacity, float loadFactor, boolean accessOrder) {
super(initialCapacity, loadFactor, accessOrder);
}
public QueryStringMap(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
}
public QueryStringMap(int initialCapacity) {
super(initialCapacity);
}
public QueryStringMap(Map extends String, ? extends List> m) {
super(m);
}
@Override
public String getParameter(String name) {
List values = get(name);
if(null != values && values.size() > 0){
return values.get(0);
}
return null;
}
@Override
public String[] getParameterValues(String name) {
List values = get(name);
if(null != values){
return values.toArray(new String[values.size()]);
}
return null;
}
@Override
public Map getParameters() {
if(null == map) {
map = new LinkedHashMap(size());
for(Entry> entry : entrySet()) {
List values = entry.getValue();
if(values.size() == 1){
map.put(entry.getKey(), values.get(0));
}else{
map.put(entry.getKey(), values.toArray(new String[values.size()]));
}
}
}
return map;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy