1 /*** 2 * Redistribution and use in source and binary forms, with or without 3 * modification, are permitted provided that the following conditions are 4 * met : 5 * 6 * . Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * 9 * . Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * . The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $Id: Configuration.java 359 2005-12-23 14:26:53Z mat007 $ 29 */ 30 31 package palmed.option; 32 33 import java.util.Hashtable; 34 35 /*** 36 * This class stores configuration keys and values. 37 * 38 * @author Mathieu Champlon 39 * @version $Revision: 359 $ $Date: 2005-12-23 23:26:53 +0900 (ven., 23 déc. 2005) $ 40 */ 41 public final class Configuration 42 { 43 /*** 44 * The configuration pairs. 45 */ 46 private final Hashtable elements_; 47 48 /*** 49 * Create a configuration manager. 50 */ 51 public Configuration() 52 { 53 elements_ = new Hashtable(); 54 } 55 56 /*** 57 * Retrieve a boolean value. 58 * <p> 59 * If the key does not exist it gets added with the initial value. 60 * 61 * @param key the key to look for 62 * @param initial the default value if the key is not found 63 * @return the value associated to the given key 64 */ 65 public boolean get( final String key, final boolean initial ) 66 { 67 return ((Boolean)get( key, new Boolean( initial ) )).booleanValue(); 68 } 69 70 /*** 71 * Retrieve a string value. 72 * <p> 73 * If the key does not exist it gets added with the initial value. 74 * 75 * @param key the key to look for 76 * @param initial the default value if the key is not found 77 * @return the value associated to the given key 78 */ 79 public String get( final String key, final String initial ) 80 { 81 return (String)get( key, (Object)initial ); 82 } 83 84 private Object get( final String key, final Object initial ) 85 { 86 if( elements_.containsKey( key ) ) 87 return elements_.get( key ); 88 elements_.put( key, initial ); 89 return initial; 90 } 91 }