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 org.apache.http.params;
29
30 import java.util.Set;
31
32 /**
33 * Abstract base class for parameter collections.
34 * Type specific setters and getters are mapped to the abstract,
35 * generic getters and setters.
36 *
37 * @since 4.0
38 *
39 * @deprecated (4.3) use configuration classes provided 'org.apache.http.config'
40 * and 'org.apache.http.client.config'
41 */
42 @Deprecated
43 public abstract class AbstractHttpParams implements HttpParams, HttpParamsNames {
44
45 /**
46 * Instantiates parameters.
47 */
48 protected AbstractHttpParams() {
49 super();
50 }
51
52 public long getLongParameter(final String name, final long defaultValue) {
53 final Object param = getParameter(name);
54 if (param == null) {
55 return defaultValue;
56 }
57 return ((Long)param).longValue();
58 }
59
60 public HttpParams setLongParameter(final String name, final long value) {
61 setParameter(name, new Long(value));
62 return this;
63 }
64
65 public int getIntParameter(final String name, final int defaultValue) {
66 final Object param = getParameter(name);
67 if (param == null) {
68 return defaultValue;
69 }
70 return ((Integer)param).intValue();
71 }
72
73 public HttpParams setIntParameter(final String name, final int value) {
74 setParameter(name, new Integer(value));
75 return this;
76 }
77
78 public double getDoubleParameter(final String name, final double defaultValue) {
79 final Object param = getParameter(name);
80 if (param == null) {
81 return defaultValue;
82 }
83 return ((Double)param).doubleValue();
84 }
85
86 public HttpParams setDoubleParameter(final String name, final double value) {
87 setParameter(name, new Double(value));
88 return this;
89 }
90
91 public boolean getBooleanParameter(final String name, final boolean defaultValue) {
92 final Object param = getParameter(name);
93 if (param == null) {
94 return defaultValue;
95 }
96 return ((Boolean)param).booleanValue();
97 }
98
99 public HttpParams setBooleanParameter(final String name, final boolean value) {
100 setParameter(name, value ? Boolean.TRUE : Boolean.FALSE);
101 return this;
102 }
103
104 public boolean isParameterTrue(final String name) {
105 return getBooleanParameter(name, false);
106 }
107
108 public boolean isParameterFalse(final String name) {
109 return !getBooleanParameter(name, false);
110 }
111
112 /**
113 * {@inheritDoc}
114 * <p/>
115 * Dummy implementation - must be overridden by subclasses.
116 *
117 * @since 4.2
118 * @throws UnsupportedOperationException - always
119 */
120 public Set<String> getNames(){
121 throw new UnsupportedOperationException();
122 }
123
124 } // class AbstractHttpParams