michael@0: /* michael@0: * ==================================================================== michael@0: * Licensed to the Apache Software Foundation (ASF) under one michael@0: * or more contributor license agreements. See the NOTICE file michael@0: * distributed with this work for additional information michael@0: * regarding copyright ownership. The ASF licenses this file michael@0: * to you under the Apache License, Version 2.0 (the michael@0: * "License"); you may not use this file except in compliance michael@0: * with the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: * ==================================================================== michael@0: * michael@0: * This software consists of voluntary contributions made by many michael@0: * individuals on behalf of the Apache Software Foundation. For more michael@0: * information on the Apache Software Foundation, please see michael@0: * . michael@0: * michael@0: */ michael@0: michael@0: package ch.boye.httpclientandroidlib.params; michael@0: michael@0: import ch.boye.httpclientandroidlib.params.HttpParams; michael@0: michael@0: /** michael@0: * Abstract base class for parameter collections. michael@0: * Type specific setters and getters are mapped to the abstract, michael@0: * generic getters and setters. michael@0: * michael@0: * @since 4.0 michael@0: */ michael@0: public abstract class AbstractHttpParams implements HttpParams { michael@0: michael@0: /** michael@0: * Instantiates parameters. michael@0: */ michael@0: protected AbstractHttpParams() { michael@0: super(); michael@0: } michael@0: michael@0: public long getLongParameter(final String name, long defaultValue) { michael@0: Object param = getParameter(name); michael@0: if (param == null) { michael@0: return defaultValue; michael@0: } michael@0: return ((Long)param).longValue(); michael@0: } michael@0: michael@0: public HttpParams setLongParameter(final String name, long value) { michael@0: setParameter(name, new Long(value)); michael@0: return this; michael@0: } michael@0: michael@0: public int getIntParameter(final String name, int defaultValue) { michael@0: Object param = getParameter(name); michael@0: if (param == null) { michael@0: return defaultValue; michael@0: } michael@0: return ((Integer)param).intValue(); michael@0: } michael@0: michael@0: public HttpParams setIntParameter(final String name, int value) { michael@0: setParameter(name, new Integer(value)); michael@0: return this; michael@0: } michael@0: michael@0: public double getDoubleParameter(final String name, double defaultValue) { michael@0: Object param = getParameter(name); michael@0: if (param == null) { michael@0: return defaultValue; michael@0: } michael@0: return ((Double)param).doubleValue(); michael@0: } michael@0: michael@0: public HttpParams setDoubleParameter(final String name, double value) { michael@0: setParameter(name, new Double(value)); michael@0: return this; michael@0: } michael@0: michael@0: public boolean getBooleanParameter(final String name, boolean defaultValue) { michael@0: Object param = getParameter(name); michael@0: if (param == null) { michael@0: return defaultValue; michael@0: } michael@0: return ((Boolean)param).booleanValue(); michael@0: } michael@0: michael@0: public HttpParams setBooleanParameter(final String name, boolean value) { michael@0: setParameter(name, value ? Boolean.TRUE : Boolean.FALSE); michael@0: return this; michael@0: } michael@0: michael@0: public boolean isParameterTrue(final String name) { michael@0: return getBooleanParameter(name, false); michael@0: } michael@0: michael@0: public boolean isParameterFalse(final String name) { michael@0: return !getBooleanParameter(name, false); michael@0: } michael@0: michael@0: } // class AbstractHttpParams