From 8f60bffa786f6c607f0d2dcf26798488553b1fbc Mon Sep 17 00:00:00 2001 From: mdb Date: Mon, 14 Oct 2002 00:23:09 +0000 Subject: [PATCH] Added means for loading subproperties into existing properties object. git-svn-id: https://samskivert.googlecode.com/svn/trunk@862 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../src/java/com/samskivert/util/Config.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/Config.java b/projects/samskivert/src/java/com/samskivert/util/Config.java index 19ebb1aa..92bb84c1 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.14 2002/05/31 17:08:40 mdb Exp $ +// $Id: Config.java,v 1.15 2002/10/14 00:23:09 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -347,12 +347,25 @@ public class Config } /** - * Returns a properties file containing all configuration values that - * start with the supplied prefix (plus a trailing "." which will be - * added if it doesn't already exist). The keys in the sub-properties - * file will have had the prefix stripped off. + * Returns a properties object containing all configuration values + * that start with the supplied prefix (plus a trailing "." which will + * be added if it doesn't already exist). The keys in the + * sub-properties will have had the prefix stripped off. */ public Properties getSubProperties (String prefix) + { + Properties props = new Properties(); + getSubProperties(prefix, props); + return props; + } + + /** + * Fills into the supplied properties object all configuration values + * that start with the supplied prefix (plus a trailing "." which will + * be added if it doesn't already exist). The keys in the + * sub-properties will have had the prefix stripped off. + */ + public void getSubProperties (String prefix, Properties target) { // slap a trailing dot on if necessary if (!prefix.endsWith(".")) { @@ -360,7 +373,6 @@ public class Config } // build the sub-properties - Properties props = new Properties(); Iterator iter = keys(); while (iter.hasNext()) { String key = (String)iter.next(); @@ -371,10 +383,8 @@ public class Config if (value == null) { continue; } - props.put(key.substring(prefix.length()), value); + target.put(key.substring(prefix.length()), value); } - - return props; } /**