1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/params/BasicHttpParams.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,160 @@ 1.4 +/* 1.5 + * ==================================================================== 1.6 + * Licensed to the Apache Software Foundation (ASF) under one 1.7 + * or more contributor license agreements. See the NOTICE file 1.8 + * distributed with this work for additional information 1.9 + * regarding copyright ownership. The ASF licenses this file 1.10 + * to you under the Apache License, Version 2.0 (the 1.11 + * "License"); you may not use this file except in compliance 1.12 + * with the License. You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, 1.17 + * software distributed under the License is distributed on an 1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1.19 + * KIND, either express or implied. See the License for the 1.20 + * specific language governing permissions and limitations 1.21 + * under the License. 1.22 + * ==================================================================== 1.23 + * 1.24 + * This software consists of voluntary contributions made by many 1.25 + * individuals on behalf of the Apache Software Foundation. For more 1.26 + * information on the Apache Software Foundation, please see 1.27 + * <http://www.apache.org/>. 1.28 + * 1.29 + */ 1.30 + 1.31 +package ch.boye.httpclientandroidlib.params; 1.32 + 1.33 +import java.io.Serializable; 1.34 +import java.util.Map; 1.35 +import java.util.HashMap; 1.36 +import java.util.Iterator; 1.37 + 1.38 +import ch.boye.httpclientandroidlib.params.HttpParams; 1.39 + 1.40 +/** 1.41 + * Default implementation of {@link HttpParams} interface. 1.42 + * <p> 1.43 + * Please note access to the internal structures of this class is not 1.44 + * synchronized and therefore this class may be thread-unsafe. 1.45 + * 1.46 + * @since 4.0 1.47 + */ 1.48 +public class BasicHttpParams extends AbstractHttpParams implements Serializable, Cloneable { 1.49 + 1.50 + private static final long serialVersionUID = -7086398485908701455L; 1.51 + 1.52 + /** Map of HTTP parameters that this collection contains. */ 1.53 + private final HashMap parameters = new HashMap(); 1.54 + 1.55 + public BasicHttpParams() { 1.56 + super(); 1.57 + } 1.58 + 1.59 + public Object getParameter(final String name) { 1.60 + return this.parameters.get(name); 1.61 + } 1.62 + 1.63 + public HttpParams setParameter(final String name, final Object value) { 1.64 + this.parameters.put(name, value); 1.65 + return this; 1.66 + } 1.67 + 1.68 + public boolean removeParameter(String name) { 1.69 + //this is to avoid the case in which the key has a null value 1.70 + if (this.parameters.containsKey(name)) { 1.71 + this.parameters.remove(name); 1.72 + return true; 1.73 + } else { 1.74 + return false; 1.75 + } 1.76 + } 1.77 + 1.78 + /** 1.79 + * Assigns the value to all the parameter with the given names 1.80 + * 1.81 + * @param names array of parameter names 1.82 + * @param value parameter value 1.83 + */ 1.84 + public void setParameters(final String[] names, final Object value) { 1.85 + for (int i = 0; i < names.length; i++) { 1.86 + setParameter(names[i], value); 1.87 + } 1.88 + } 1.89 + 1.90 + /** 1.91 + * Is the parameter set? 1.92 + * <p> 1.93 + * Uses {@link #getParameter(String)} (which is overrideable) to 1.94 + * fetch the parameter value, if any. 1.95 + * <p> 1.96 + * Also @see {@link #isParameterSetLocally(String)} 1.97 + * 1.98 + * @param name parameter name 1.99 + * @return true if parameter is defined and non-null 1.100 + */ 1.101 + public boolean isParameterSet(final String name) { 1.102 + return getParameter(name) != null; 1.103 + } 1.104 + 1.105 + /** 1.106 + * Is the parameter set in this object? 1.107 + * <p> 1.108 + * The parameter value is fetched directly. 1.109 + * <p> 1.110 + * Also @see {@link #isParameterSet(String)} 1.111 + * 1.112 + * @param name parameter name 1.113 + * @return true if parameter is defined and non-null 1.114 + */ 1.115 + public boolean isParameterSetLocally(final String name) { 1.116 + return this.parameters.get(name) != null; 1.117 + } 1.118 + 1.119 + /** 1.120 + * Removes all parameters from this collection. 1.121 + */ 1.122 + public void clear() { 1.123 + this.parameters.clear(); 1.124 + } 1.125 + 1.126 + /** 1.127 + * Creates a copy of these parameters. 1.128 + * This implementation calls {@link #clone()}. 1.129 + * 1.130 + * @return a new set of params holding a copy of the 1.131 + * <i>local</i> parameters in this object. 1.132 + * 1.133 + * @deprecated 1.134 + * @throws UnsupportedOperationException if the clone() fails 1.135 + */ 1.136 + public HttpParams copy() { 1.137 + try { 1.138 + return (HttpParams) clone(); 1.139 + } catch (CloneNotSupportedException ex) { 1.140 + throw new UnsupportedOperationException("Cloning not supported"); 1.141 + } 1.142 + } 1.143 + 1.144 + /** 1.145 + * Clones the instance. 1.146 + * Uses {@link #copyParams(HttpParams)} to copy the parameters. 1.147 + */ 1.148 + public Object clone() throws CloneNotSupportedException { 1.149 + BasicHttpParams clone = (BasicHttpParams) super.clone(); 1.150 + copyParams(clone); 1.151 + return clone; 1.152 + } 1.153 + 1.154 + protected void copyParams(HttpParams target) { 1.155 + Iterator iter = parameters.entrySet().iterator(); 1.156 + while (iter.hasNext()) { 1.157 + Map.Entry me = (Map.Entry) iter.next(); 1.158 + if (me.getKey() instanceof String) 1.159 + target.setParameter((String)me.getKey(), me.getValue()); 1.160 + } 1.161 + } 1.162 + 1.163 +}