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 public abstract class AbstractHttpParams implements HttpParams { 48 49 /** 50 * Instantiates parameters. 51 */ AbstractHttpParams()52 protected AbstractHttpParams() { 53 super(); 54 } 55 getLongParameter(final String name, long defaultValue)56 public long getLongParameter(final String name, long defaultValue) { 57 Object param = getParameter(name); 58 if (param == null) { 59 return defaultValue; 60 } 61 return ((Long)param).longValue(); 62 } 63 setLongParameter(final String name, long value)64 public HttpParams setLongParameter(final String name, long value) { 65 setParameter(name, new Long(value)); 66 return this; 67 } 68 getIntParameter(final String name, int defaultValue)69 public int getIntParameter(final String name, int defaultValue) { 70 Object param = getParameter(name); 71 if (param == null) { 72 return defaultValue; 73 } 74 return ((Integer)param).intValue(); 75 } 76 setIntParameter(final String name, int value)77 public HttpParams setIntParameter(final String name, int value) { 78 setParameter(name, new Integer(value)); 79 return this; 80 } 81 getDoubleParameter(final String name, double defaultValue)82 public double getDoubleParameter(final String name, double defaultValue) { 83 Object param = getParameter(name); 84 if (param == null) { 85 return defaultValue; 86 } 87 return ((Double)param).doubleValue(); 88 } 89 setDoubleParameter(final String name, double value)90 public HttpParams setDoubleParameter(final String name, double value) { 91 setParameter(name, new Double(value)); 92 return this; 93 } 94 getBooleanParameter(final String name, boolean defaultValue)95 public boolean getBooleanParameter(final String name, boolean defaultValue) { 96 Object param = getParameter(name); 97 if (param == null) { 98 return defaultValue; 99 } 100 return ((Boolean)param).booleanValue(); 101 } 102 setBooleanParameter(final String name, boolean value)103 public HttpParams setBooleanParameter(final String name, boolean value) { 104 setParameter(name, value ? Boolean.TRUE : Boolean.FALSE); 105 return this; 106 } 107 isParameterTrue(final String name)108 public boolean isParameterTrue(final String name) { 109 return getBooleanParameter(name, false); 110 } 111 isParameterFalse(final String name)112 public boolean isParameterFalse(final String name) { 113 return !getBooleanParameter(name, false); 114 } 115 116 } // class AbstractHttpParams 117