View Javadoc

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      @Override
53      public long getLongParameter(final String name, final long defaultValue) {
54          final Object param = getParameter(name);
55          if (param == null) {
56              return defaultValue;
57          }
58          return ((Long) param).longValue();
59      }
60  
61      @Override
62      public HttpParams setLongParameter(final String name, final long value) {
63          setParameter(name, Long.valueOf(value));
64          return this;
65      }
66  
67      @Override
68      public int getIntParameter(final String name, final int defaultValue) {
69          final Object param = getParameter(name);
70          if (param == null) {
71              return defaultValue;
72          }
73          return ((Integer) param).intValue();
74      }
75  
76      @Override
77      public HttpParams setIntParameter(final String name, final int value) {
78          setParameter(name, Integer.valueOf(value));
79          return this;
80      }
81  
82      @Override
83      public double getDoubleParameter(final String name, final double defaultValue) {
84          final Object param = getParameter(name);
85          if (param == null) {
86              return defaultValue;
87          }
88          return ((Double) param).doubleValue();
89      }
90  
91      @Override
92      public HttpParams setDoubleParameter(final String name, final double value) {
93          setParameter(name, Double.valueOf(value));
94          return this;
95      }
96  
97      @Override
98      public boolean getBooleanParameter(final String name, final boolean defaultValue) {
99          final Object param = getParameter(name);
100         if (param == null) {
101             return defaultValue;
102         }
103         return ((Boolean) param).booleanValue();
104     }
105 
106     @Override
107     public HttpParams setBooleanParameter(final String name, final boolean value) {
108         setParameter(name, value ? Boolean.TRUE : Boolean.FALSE);
109         return this;
110     }
111 
112     @Override
113     public boolean isParameterTrue(final String name) {
114         return getBooleanParameter(name, false);
115     }
116 
117     @Override
118     public boolean isParameterFalse(final String name) {
119         return !getBooleanParameter(name, false);
120     }
121 
122     /**
123      * {@inheritDoc}
124      * <p/>
125      * Dummy implementation - must be overridden by subclasses.
126      *
127      * @since 4.2
128      * @throws UnsupportedOperationException - always
129      */
130     @Override
131     public Set<String> getNames(){
132         throw new UnsupportedOperationException();
133     }
134 
135 } // class AbstractHttpParams