Home | History | Annotate | Download | only in params
      1 /*
      2  * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/AbstractHttpParams.java $
      3  * $Revision: 542224 $
      4  * $Date: 2007-05-28 06:34:04 -0700 (Mon, 28 May 2007) $
      5  *
      6  * ====================================================================
      7  * Licensed to the Apache Software Foundation (ASF) under one
      8  * or more contributor license agreements.  See the NOTICE file
      9  * distributed with this work for additional information
     10  * regarding copyright ownership.  The ASF licenses this file
     11  * to you under the Apache License, Version 2.0 (the
     12  * "License"); you may not use this file except in compliance
     13  * with the License.  You may obtain a copy of the License at
     14  *
     15  *   http://www.apache.org/licenses/LICENSE-2.0
     16  *
     17  * Unless required by applicable law or agreed to in writing,
     18  * software distributed under the License is distributed on an
     19  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     20  * KIND, either express or implied.  See the License for the
     21  * specific language governing permissions and limitations
     22  * under the License.
     23  * ====================================================================
     24  *
     25  * This software consists of voluntary contributions made by many
     26  * individuals on behalf of the Apache Software Foundation.  For more
     27  * information on the Apache Software Foundation, please see
     28  * <http://www.apache.org/>.
     29  *
     30  */
     31 
     32 package org.apache.http.params;
     33 
     34 import org.apache.http.params.HttpParams;
     35 
     36 
     37 /**
     38  * Abstract base class for parameter collections.
     39  * Type specific setters and getters are mapped to the abstract,
     40  * generic getters and setters.
     41  *
     42  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
     43  * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
     44  *
     45  * @version $Revision: 542224 $
     46  *
     47  * @deprecated Please use {@link java.net.URL#openConnection} instead.
     48  *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
     49  *     for further details.
     50  */
     51 @Deprecated
     52 public abstract class AbstractHttpParams implements HttpParams {
     53 
     54     /**
     55      * Instantiates parameters.
     56      */
     57     protected AbstractHttpParams() {
     58         super();
     59     }
     60 
     61     public long getLongParameter(final String name, long defaultValue) {
     62         Object param = getParameter(name);
     63         if (param == null) {
     64             return defaultValue;
     65         }
     66         return ((Long)param).longValue();
     67     }
     68 
     69     public HttpParams setLongParameter(final String name, long value) {
     70         setParameter(name, new Long(value));
     71         return this;
     72     }
     73 
     74     public int getIntParameter(final String name, int defaultValue) {
     75         Object param = getParameter(name);
     76         if (param == null) {
     77             return defaultValue;
     78         }
     79         return ((Integer)param).intValue();
     80     }
     81 
     82     public HttpParams setIntParameter(final String name, int value) {
     83         setParameter(name, new Integer(value));
     84         return this;
     85     }
     86 
     87     public double getDoubleParameter(final String name, double defaultValue) {
     88         Object param = getParameter(name);
     89         if (param == null) {
     90             return defaultValue;
     91         }
     92         return ((Double)param).doubleValue();
     93     }
     94 
     95     public HttpParams setDoubleParameter(final String name, double value) {
     96         setParameter(name, new Double(value));
     97         return this;
     98     }
     99 
    100     public boolean getBooleanParameter(final String name, boolean defaultValue) {
    101         Object param = getParameter(name);
    102         if (param == null) {
    103             return defaultValue;
    104         }
    105         return ((Boolean)param).booleanValue();
    106     }
    107 
    108     public HttpParams setBooleanParameter(final String name, boolean value) {
    109         setParameter(name, value ? Boolean.TRUE : Boolean.FALSE);
    110         return this;
    111     }
    112 
    113     public boolean isParameterTrue(final String name) {
    114         return getBooleanParameter(name, false);
    115     }
    116 
    117     public boolean isParameterFalse(final String name) {
    118         return !getBooleanParameter(name, false);
    119     }
    120 
    121 } // class AbstractHttpParams
    122