From 09e16347112470afd6c51ccf36b91afecd4ead7a Mon Sep 17 00:00:00 2001 From: ray Date: Thu, 9 Dec 2004 01:33:43 +0000 Subject: [PATCH] Support long[] values. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1541 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../src/java/com/samskivert/util/Config.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/projects/samskivert/src/java/com/samskivert/util/Config.java b/projects/samskivert/src/java/com/samskivert/util/Config.java index 676c7c47..12f7e713 100644 --- a/projects/samskivert/src/java/com/samskivert/util/Config.java +++ b/projects/samskivert/src/java/com/samskivert/util/Config.java @@ -436,6 +436,51 @@ public class Config _propsup.firePropertyChange(name, oldValue, 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 the name of the property to be fetched. + * @param defval the value to return if the property is not specified + * in the config file. + * + * @return the value of the requested property. + */ + public long[] getValue (String name, long[] defval) + { + // look up the value in the configuration file and use that to + // look up any overridden value + String val = _prefs.get(name, _props.getProperty(name)); + long[] result = defval; + + // parse it into an array of longs + if (val != null) { + result = StringUtil.parseLongArray(val); + if (result == null) { + Log.warning("Malformed int array property [name=" + name + + ", value=" + val + "]."); + return defval; + } + } + + return result; + } + + /** + * Sets the value of the specified preference, overriding the value + * defined in the configuration files shipped with the application. + */ + public void setValue (String name, long[] value) + { + long[] oldValue = getValue(name, (long[])null); + _prefs.put(name, StringUtil.toString(value, "", "")); + _propsup.firePropertyChange(name, oldValue, value); + } + /** * Fetches and returns the value for the specified configuration * property. If the value is not specified in the associated