|
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 import ch.boye.httpclientandroidlib.params.HttpParams; |
|
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 public abstract class AbstractHttpParams implements HttpParams { |
|
40 |
|
41 /** |
|
42 * Instantiates parameters. |
|
43 */ |
|
44 protected AbstractHttpParams() { |
|
45 super(); |
|
46 } |
|
47 |
|
48 public long getLongParameter(final String name, long defaultValue) { |
|
49 Object param = getParameter(name); |
|
50 if (param == null) { |
|
51 return defaultValue; |
|
52 } |
|
53 return ((Long)param).longValue(); |
|
54 } |
|
55 |
|
56 public HttpParams setLongParameter(final String name, long value) { |
|
57 setParameter(name, new Long(value)); |
|
58 return this; |
|
59 } |
|
60 |
|
61 public int getIntParameter(final String name, int defaultValue) { |
|
62 Object param = getParameter(name); |
|
63 if (param == null) { |
|
64 return defaultValue; |
|
65 } |
|
66 return ((Integer)param).intValue(); |
|
67 } |
|
68 |
|
69 public HttpParams setIntParameter(final String name, int value) { |
|
70 setParameter(name, new Integer(value)); |
|
71 return this; |
|
72 } |
|
73 |
|
74 public double getDoubleParameter(final String name, double defaultValue) { |
|
75 Object param = getParameter(name); |
|
76 if (param == null) { |
|
77 return defaultValue; |
|
78 } |
|
79 return ((Double)param).doubleValue(); |
|
80 } |
|
81 |
|
82 public HttpParams setDoubleParameter(final String name, double value) { |
|
83 setParameter(name, new Double(value)); |
|
84 return this; |
|
85 } |
|
86 |
|
87 public boolean getBooleanParameter(final String name, boolean defaultValue) { |
|
88 Object param = getParameter(name); |
|
89 if (param == null) { |
|
90 return defaultValue; |
|
91 } |
|
92 return ((Boolean)param).booleanValue(); |
|
93 } |
|
94 |
|
95 public HttpParams setBooleanParameter(final String name, boolean value) { |
|
96 setParameter(name, value ? Boolean.TRUE : Boolean.FALSE); |
|
97 return this; |
|
98 } |
|
99 |
|
100 public boolean isParameterTrue(final String name) { |
|
101 return getBooleanParameter(name, false); |
|
102 } |
|
103 |
|
104 public boolean isParameterFalse(final String name) { |
|
105 return !getBooleanParameter(name, false); |
|
106 } |
|
107 |
|
108 } // class AbstractHttpParams |