001/*
002 * ====================================================================
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 * ====================================================================
020 *
021 * This software consists of voluntary contributions made by many
022 * individuals on behalf of the Apache Software Foundation.  For more
023 * information on the Apache Software Foundation, please see
024 * <http://www.apache.org/>.
025 *
026 */
027
028package org.apache.http.params;
029
030import java.util.Set;
031
032/**
033 * Abstract base class for parameter collections.
034 * Type specific setters and getters are mapped to the abstract,
035 * generic getters and setters.
036 *
037 * @since 4.0
038 *
039 * @deprecated (4.3) use configuration classes provided 'org.apache.http.config'
040 *  and 'org.apache.http.client.config'
041 */
042@Deprecated
043public abstract class AbstractHttpParams implements HttpParams, HttpParamsNames {
044
045    /**
046     * Instantiates parameters.
047     */
048    protected AbstractHttpParams() {
049        super();
050    }
051
052    @Override
053    public long getLongParameter(final String name, final long defaultValue) {
054        final Object param = getParameter(name);
055        if (param == null) {
056            return defaultValue;
057        }
058        return ((Long) param).longValue();
059    }
060
061    @Override
062    public HttpParams setLongParameter(final String name, final long value) {
063        setParameter(name, Long.valueOf(value));
064        return this;
065    }
066
067    @Override
068    public int getIntParameter(final String name, final int defaultValue) {
069        final Object param = getParameter(name);
070        if (param == null) {
071            return defaultValue;
072        }
073        return ((Integer) param).intValue();
074    }
075
076    @Override
077    public HttpParams setIntParameter(final String name, final int value) {
078        setParameter(name, Integer.valueOf(value));
079        return this;
080    }
081
082    @Override
083    public double getDoubleParameter(final String name, final double defaultValue) {
084        final Object param = getParameter(name);
085        if (param == null) {
086            return defaultValue;
087        }
088        return ((Double) param).doubleValue();
089    }
090
091    @Override
092    public HttpParams setDoubleParameter(final String name, final double value) {
093        setParameter(name, Double.valueOf(value));
094        return this;
095    }
096
097    @Override
098    public boolean getBooleanParameter(final String name, final boolean defaultValue) {
099        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