From 19bc14ce454309bb2e7a0bd8a303589d2ae9dd14 Mon Sep 17 00:00:00 2001 From: ray Date: Wed, 13 Nov 2002 07:12:31 +0000 Subject: [PATCH] Added support for float values. git-svn-id: https://samskivert.googlecode.com/svn/trunk@934 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../src/java/com/samskivert/util/Config.java | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/Config.java b/projects/samskivert/src/java/com/samskivert/util/Config.java index 92bb84c1..72adf024 100644 --- a/projects/samskivert/src/java/com/samskivert/util/Config.java +++ b/projects/samskivert/src/java/com/samskivert/util/Config.java @@ -1,5 +1,5 @@ // -// $Id: Config.java,v 1.15 2002/10/14 00:23:09 mdb Exp $ +// $Id: Config.java,v 1.16 2002/11/13 07:12:31 ray Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -175,6 +175,46 @@ public class Config _prefs.putLong(name, value); } + /** + * Fetches and returns the value for the specified configuration + * property. If the value is not specified in the associated + * properties file, the supplied default value is returned instead. If + * the property specified in the file is poorly formatted (not and + * integer, not in proper array specification), a warning message will + * be logged and the default value will be returned. + * + * @param name name of the property. + * @param defval the value to return if the property is not specified + * in the config file. + * + * @return the value of the requested property. + */ + public float getValue (String name, float defval) + { + // if there is a value, parse it into an integer + String val = _props.getProperty(name); + if (val != null) { + try { + defval = Float.parseFloat(val); + } catch (NumberFormatException nfe) { + Log.warning("Malformed float property [name=" + name + + ", value=" + val + "]."); + } + } + + // finally look for an overridden value + return _prefs.getFloat(name, defval); + } + + /** + * Sets the value of the specified preference, overriding the value + * defined in the configuration files shipped with the application. + */ + public void setValue (String name, float value) + { + _prefs.putFloat(name, value); + } + /** * Fetches and returns the value for the specified configuration * property. If the value is not specified in the associated