commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1799505 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration2/ test/java/org/apache/commons/configuration2/
Date Wed, 21 Jun 2017 20:01:00 GMT
Author: oheger
Date: Wed Jun 21 20:01:00 2017
New Revision: 1799505

URL: http://svn.apache.org/viewvc?rev=1799505&view=rev
Log:
[CONFIGURATION-258] Added copy constructors.

Like other hierarchical configurations, JSONConfiguration and
YAMLConfiguration should have a copy constructor.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/AbstractYAMLBasedConfiguration.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/JSONConfiguration.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/YAMLConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestJSONConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestYAMLConfiguration.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/AbstractYAMLBasedConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/AbstractYAMLBasedConfiguration.java?rev=1799505&r1=1799504&r2=1799505&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/AbstractYAMLBasedConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/AbstractYAMLBasedConfiguration.java
Wed Jun 21 20:01:00 2017
@@ -48,6 +48,19 @@ public class AbstractYAMLBasedConfigurat
     }
 
     /**
+     * Creates a new instance of {@code AbstractYAMLBasedConfiguration} as a
+     * copy of the specified configuration.
+     *
+     * @param c the configuration to be copied
+     */
+    protected AbstractYAMLBasedConfiguration(
+            HierarchicalConfiguration<ImmutableNode> c)
+    {
+        super(c);
+        initLogger(new ConfigurationLogger(getClass()));
+    }
+
+    /**
      * Loads this configuration from the content of the specified map. The data
      * in the map is transformed into a hierarchy of {@link ImmutableNode}
      * objects.

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/JSONConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/JSONConfiguration.java?rev=1799505&r1=1799504&r2=1799505&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/JSONConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/JSONConfiguration.java
Wed Jun 21 20:01:00 2017
@@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.Ob
 import com.fasterxml.jackson.databind.type.MapType;
 import org.apache.commons.configuration2.ex.ConfigurationException;
 import org.apache.commons.configuration2.io.InputStreamSupport;
+import org.apache.commons.configuration2.tree.ImmutableNode;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -51,6 +52,17 @@ public class JSONConfiguration extends A
         super();
     }
 
+    /**
+     * Creates a new instance of {@code JSONConfiguration} as a copy of the
+     * specified configuration.
+     *
+     * @param c the configuration to be copied
+     */
+    public JSONConfiguration(HierarchicalConfiguration<ImmutableNode> c)
+    {
+        super(c);
+    }
+
     @Override
     public void read(Reader in) throws ConfigurationException
     {

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/YAMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/YAMLConfiguration.java?rev=1799505&r1=1799504&r2=1799505&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/YAMLConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/YAMLConfiguration.java
Wed Jun 21 20:01:00 2017
@@ -19,6 +19,7 @@ package org.apache.commons.configuration
 
 import org.apache.commons.configuration2.ex.ConfigurationException;
 import org.apache.commons.configuration2.io.InputStreamSupport;
+import org.apache.commons.configuration2.tree.ImmutableNode;
 import org.yaml.snakeyaml.DumperOptions;
 import org.yaml.snakeyaml.LoaderOptions;
 import org.yaml.snakeyaml.Yaml;
@@ -48,6 +49,17 @@ public class YAMLConfiguration extends A
         super();
     }
 
+    /**
+     * Creates a new instance of {@code YAMLConfiguration} as a copy of the
+     * specified configuration.
+     *
+     * @param c the configuration to be copied
+     */
+    public YAMLConfiguration(HierarchicalConfiguration<ImmutableNode> c)
+    {
+        super(c);
+    }
+
     @Override
     public void read(Reader in) throws ConfigurationException
     {

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestJSONConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestJSONConfiguration.java?rev=1799505&r1=1799504&r2=1799505&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestJSONConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestJSONConfiguration.java
Wed Jun 21 20:01:00 2017
@@ -130,4 +130,13 @@ public class TestJSONConfiguration
         assertEquals("Elite", jsonConfiguration.getProperty("martin.skill"));
     }
 
+    @Test
+    public void testCopyConstructor()
+    {
+        BaseHierarchicalConfiguration c = new BaseHierarchicalConfiguration();
+        c.addProperty("foo", "bar");
+
+        jsonConfiguration = new JSONConfiguration(c);
+        assertEquals("bar", jsonConfiguration.getString("foo"));
+    }
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestYAMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestYAMLConfiguration.java?rev=1799505&r1=1799504&r2=1799505&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestYAMLConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestYAMLConfiguration.java
Wed Jun 21 20:01:00 2017
@@ -110,4 +110,14 @@ public class TestYAMLConfiguration
         assertEquals("Developer", yamlConfiguration.getProperty("martin.job"));
         assertEquals("Elite", yamlConfiguration.getProperty("martin.skill"));
     }
+
+    @Test
+    public void testCopyConstructor()
+    {
+        BaseHierarchicalConfiguration c = new BaseHierarchicalConfiguration();
+        c.addProperty("foo", "bar");
+
+        yamlConfiguration = new YAMLConfiguration(c);
+        assertEquals("bar", yamlConfiguration.getString("foo"));
+    }
 }



Mime
View raw message