commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1405916 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/ test/java/org/apache/commons/configuration/
Date Mon, 05 Nov 2012 18:43:48 GMT
Author: oheger
Date: Mon Nov  5 18:43:48 2012
New Revision: 1405916

URL: http://svn.apache.org/viewvc?rev=1405916&view=rev
Log:
Added support for immutable subsets.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ImmutableConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestImmutableConfiguration.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java?rev=1405916&r1=1405915&r2=1405916&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java
Mon Nov  5 18:43:48 2012
@@ -29,9 +29,9 @@ import java.util.List;
 import java.util.NoSuchElementException;
 import java.util.Properties;
 
+import org.apache.commons.configuration.event.BaseEventSource;
 import org.apache.commons.configuration.event.ConfigurationErrorEvent;
 import org.apache.commons.configuration.event.ConfigurationErrorListener;
-import org.apache.commons.configuration.event.BaseEventSource;
 import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
 import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.ClassUtils;
@@ -476,6 +476,11 @@ public abstract class AbstractConfigurat
         return new SubsetConfiguration(this, prefix, ".");
     }
 
+    public ImmutableConfiguration immutableSubset(String prefix)
+    {
+        return ConfigurationUtils.unmodifiableConfiguration(subset(prefix));
+    }
+
     public void setProperty(String key, Object value)
     {
         fireEvent(EVENT_SET_PROPERTY, key, value, true);

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ImmutableConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ImmutableConfiguration.java?rev=1405916&r1=1405915&r2=1405916&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ImmutableConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ImmutableConfiguration.java
Mon Nov  5 18:43:48 2012
@@ -515,4 +515,30 @@ public interface ImmutableConfiguration
      *         object that is not a List.
      */
     List<Object> getList(String key, List<Object> defaultValue);
+    /**
+     * Return a decorator immutable Configuration containing every key from the current
+     * Configuration that starts with the specified prefix. The prefix is
+     * removed from the keys in the subset. For example, if the configuration
+     * contains the following properties:
+     *
+     * <pre>
+     *    prefix.number = 1
+     *    prefix.string = Apache
+     *    prefixed.foo = bar
+     *    prefix = Jakarta</pre>
+     *
+     * the immutable Configuration returned by {@code subset("prefix")} will contain
+     * the properties:
+     *
+     * <pre>
+     *    number = 1
+     *    string = Apache
+     *    = Jakarta</pre>
+     *
+     * (The key for the value "Jakarta" is an empty string)
+     *
+     * @param prefix The prefix used to select the properties.
+     * @return a subset immutable configuration
+     */
+    ImmutableConfiguration immutableSubset(String prefix);
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestImmutableConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestImmutableConfiguration.java?rev=1405916&r1=1405915&r2=1405916&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestImmutableConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestImmutableConfiguration.java
Mon Nov  5 18:43:48 2012
@@ -176,4 +176,18 @@ public class TestImmutableConfiguration
         Configuration mutableConf = (Configuration) conf;
         mutableConf.clear();
     }
+
+    /**
+     * Tests whether an immutable subset can be queried.
+     */
+    @Test
+    public void testImmutableSubset() throws ConfigurationException
+    {
+        ImmutableConfiguration conf =
+                ConfigurationUtils
+                        .unmodifiableConfiguration(createTestConfig());
+        ImmutableConfiguration subset = conf.immutableSubset("test");
+        assertFalse("No content", subset.isEmpty());
+        assertEquals("Wrong value", 1000000, subset.getLong("long"));
+    }
 }



Mime
View raw message