Added a method to create a Properties object that accesses subproperties

by filtering a referenced base Properties, rather than creating an 
entirely new set of Properties, to avoid creating loads of garbage when 
filtering through multiple levels of subproperties.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1943 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
andrzej
2006-10-11 18:41:08 +00:00
parent 4607cf4b6a
commit 5ad5f22e7c
@@ -92,6 +92,38 @@ public class PropertiesUtil
return dest;
}
/**
* Returns a filtered version of the specified properties that first
* looks for a property starting with the given prefix, then looks for
* a property without the prefix. For example, passing the prefix "alt"
* and using the following properties:
*
* <pre>
* alt.texture = sand.png
* lighting = off
* </pre>
*
* ...would return "sand.png" for the property "texture" and "off" for
* the property "lighting". Unlike {@link #getSubProperties}, the object
* returned by this method references, rather than copies, the underlying
* properties. Only the {@link Properties#getProperty} methods are
* guaranteed to work correctly on the returned object.
*/
public static Properties getFilteredProperties (
final Properties source, String prefix)
{
final String dprefix = prefix + ".";
return new Properties() {
public String getProperty (String key) {
return getProperty(key, null);
}
public String getProperty (String key, String defaultValue) {
return source.getProperty(dprefix + key,
source.getProperty(key, defaultValue));
}
};
}
/**
* A helper function used by the {@link #getSubProperties} methods.
*/