001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/main/java/org/apache/http/params/AbstractHttpParams.java $
003: * $Revision: 542224 $
004: * $Date: 2007-05-28 15:34:04 +0200 (Mon, 28 May 2007) $
005: *
006: * ====================================================================
007: * Licensed to the Apache Software Foundation (ASF) under one
008: * or more contributor license agreements. See the NOTICE file
009: * distributed with this work for additional information
010: * regarding copyright ownership. The ASF licenses this file
011: * to you under the Apache License, Version 2.0 (the
012: * "License"); you may not use this file except in compliance
013: * with the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing,
018: * software distributed under the License is distributed on an
019: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020: * KIND, either express or implied. See the License for the
021: * specific language governing permissions and limitations
022: * under the License.
023: * ====================================================================
024: *
025: * This software consists of voluntary contributions made by many
026: * individuals on behalf of the Apache Software Foundation. For more
027: * information on the Apache Software Foundation, please see
028: * <http://www.apache.org/>.
029: *
030: */
031:
032: package org.apache.http.params;
033:
034: import org.apache.http.params.HttpParams;
035:
036: /**
037: * Abstract base class for parameter collections.
038: * Type specific setters and getters are mapped to the abstract,
039: * generic getters and setters.
040: *
041: * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
042: * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
043: *
044: * @version $Revision: 542224 $
045: */
046: public abstract class AbstractHttpParams implements HttpParams {
047:
048: /**
049: * Instantiates parameters.
050: */
051: protected AbstractHttpParams() {
052: super ();
053: }
054:
055: public long getLongParameter(final String name, long defaultValue) {
056: Object param = getParameter(name);
057: if (param == null) {
058: return defaultValue;
059: }
060: return ((Long) param).longValue();
061: }
062:
063: public HttpParams setLongParameter(final String name, long value) {
064: setParameter(name, new Long(value));
065: return this ;
066: }
067:
068: public int getIntParameter(final String name, int defaultValue) {
069: Object param = getParameter(name);
070: if (param == null) {
071: return defaultValue;
072: }
073: return ((Integer) param).intValue();
074: }
075:
076: public HttpParams setIntParameter(final String name, int value) {
077: setParameter(name, new Integer(value));
078: return this ;
079: }
080:
081: public double getDoubleParameter(final String name,
082: double defaultValue) {
083: Object param = getParameter(name);
084: if (param == null) {
085: return defaultValue;
086: }
087: return ((Double) param).doubleValue();
088: }
089:
090: public HttpParams setDoubleParameter(final String name, double value) {
091: setParameter(name, new Double(value));
092: return this ;
093: }
094:
095: public boolean getBooleanParameter(final String name,
096: boolean defaultValue) {
097: Object param = getParameter(name);
098: if (param == null) {
099: return defaultValue;
100: }
101: return ((Boolean) param).booleanValue();
102: }
103:
104: public HttpParams setBooleanParameter(final String name,
105: boolean value) {
106: setParameter(name, value ? Boolean.TRUE : Boolean.FALSE);
107: return this ;
108: }
109:
110: public boolean isParameterTrue(final String name) {
111: return getBooleanParameter(name, false);
112: }
113:
114: public boolean isParameterFalse(final String name) {
115: return !getBooleanParameter(name, false);
116: }
117:
118: } // class AbstractHttpParams
|