mobile/android/thirdparty/ch/boye/httpclientandroidlib/params/DefaultedHttpParams.java

branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
equal deleted inserted replaced
-1:000000000000 0:4cd992b6fc68
1 /*
2 * ====================================================================
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 * ====================================================================
20 *
21 * This software consists of voluntary contributions made by many
22 * individuals on behalf of the Apache Software Foundation. For more
23 * information on the Apache Software Foundation, please see
24 * <http://www.apache.org/>.
25 *
26 */
27
28 package ch.boye.httpclientandroidlib.params;
29
30 /**
31 * {@link HttpParams} implementation that delegates resolution of a parameter
32 * to the given default {@link HttpParams} instance if the parameter is not
33 * present in the local one. The state of the local collection can be mutated,
34 * whereas the default collection is treated as read-only.
35 *
36 * @since 4.0
37 */
38 public final class DefaultedHttpParams extends AbstractHttpParams {
39
40 private final HttpParams local;
41 private final HttpParams defaults;
42
43 /**
44 * Create the defaulted set of HttpParams.
45 *
46 * @param local the mutable set of HttpParams
47 * @param defaults the default set of HttpParams, not mutated by this class
48 */
49 public DefaultedHttpParams(final HttpParams local, final HttpParams defaults) {
50 super();
51 if (local == null) {
52 throw new IllegalArgumentException("HTTP parameters may not be null");
53 }
54 this.local = local;
55 this.defaults = defaults;
56 }
57
58 /**
59 * Creates a copy of the local collection with the same default
60 *
61 * @deprecated
62 */
63 public HttpParams copy() {
64 HttpParams clone = this.local.copy();
65 return new DefaultedHttpParams(clone, this.defaults);
66 }
67
68 /**
69 * Retrieves the value of the parameter from the local collection and, if the
70 * parameter is not set locally, delegates its resolution to the default
71 * collection.
72 */
73 public Object getParameter(final String name) {
74 Object obj = this.local.getParameter(name);
75 if (obj == null && this.defaults != null) {
76 obj = this.defaults.getParameter(name);
77 }
78 return obj;
79 }
80
81 /**
82 * Attempts to remove the parameter from the local collection. This method
83 * <i>does not</i> modify the default collection.
84 */
85 public boolean removeParameter(final String name) {
86 return this.local.removeParameter(name);
87 }
88
89 /**
90 * Sets the parameter in the local collection. This method <i>does not</i>
91 * modify the default collection.
92 */
93 public HttpParams setParameter(final String name, final Object value) {
94 return this.local.setParameter(name, value);
95 }
96
97 /**
98 *
99 * @return the default HttpParams collection
100 */
101 public HttpParams getDefaults() {
102 return this.defaults;
103 }
104
105 }

mercurial