Added means for loading subproperties into existing properties object.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@862 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2002-10-14 00:23:09 +00:00
parent 7dceb9c255
commit 8f60bffa78
@@ -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 // samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne // Copyright (C) 2001 Michael Bayne
@@ -347,12 +347,25 @@ public class Config
} }
/** /**
* Returns a properties file containing all configuration values that * Returns a properties object containing all configuration values
* start with the supplied prefix (plus a trailing "." which will be * that start with the supplied prefix (plus a trailing "." which will
* added if it doesn't already exist). The keys in the sub-properties * be added if it doesn't already exist). The keys in the
* file will have had the prefix stripped off. * sub-properties will have had the prefix stripped off.
*/ */
public Properties getSubProperties (String prefix) 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 // slap a trailing dot on if necessary
if (!prefix.endsWith(".")) { if (!prefix.endsWith(".")) {
@@ -360,7 +373,6 @@ public class Config
} }
// build the sub-properties // build the sub-properties
Properties props = new Properties();
Iterator iter = keys(); Iterator iter = keys();
while (iter.hasNext()) { while (iter.hasNext()) {
String key = (String)iter.next(); String key = (String)iter.next();
@@ -371,10 +383,8 @@ public class Config
if (value == null) { if (value == null) {
continue; continue;
} }
props.put(key.substring(prefix.length()), value); target.put(key.substring(prefix.length()), value);
} }
return props;
} }
/** /**