Author: oheger
Date: Wed Jun 21 20:00:35 2017
New Revision: 1799502

URL: http://svn.apache.org/viewvc?rev=1799502&view=rev
Log:
[CONFIGURATION-258] Some polishing of the original patch.

Applied formatting rules, removed @author tags, added missing
license headers, removed unused imports and unused private
methods.

Modified:
    
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/AbstractMapBasedConfiguration.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/AbstractMapBasedConfiguration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/AbstractMapBasedConfiguration.java?rev=1799502&r1=1799501&r2=1799502&view=diff
==============================================================================
--- 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/AbstractMapBasedConfiguration.java
 (original)
+++ 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/AbstractMapBasedConfiguration.java
 Wed Jun 21 20:00:35 2017
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.commons.configuration2;
 
 import org.apache.commons.configuration2.ex.ConfigurationException;
@@ -10,30 +27,31 @@ import java.util.Map;
 /**
  * @author The-Alchemist
  */
-public class AbstractMapBasedConfiguration extends 
BaseHierarchicalConfiguration {
-
-    public AbstractMapBasedConfiguration() {
-        super();
-
+public class AbstractMapBasedConfiguration extends 
BaseHierarchicalConfiguration
+{
+    protected AbstractMapBasedConfiguration()
+    {
         initLogger(new ConfigurationLogger(getClass()));
     }
 
-    protected void load(Map<String, Object> map) {
+    protected void load(Map<String, Object> map)
+    {
         ImmutableNode.Builder rootBuilder = new ImmutableNode.Builder();
         ImmutableNode top = constructHierarchy(rootBuilder, map);
         getNodeModel().setRootNode(top);
     }
 
     /**
-     * Constructs a YAML map, i.e. String -> Object from a given
-     * configuration node.
+     * Constructs a YAML map, i.e. String -> Object from a given configuration
+     * node.
      *
      * @param node The configuration node to create a map from.
      * @return A Map that contains the configuration node information.
      */
     protected Map<String, Object> constructMap(ImmutableNode node)
     {
-        Map<String, Object> map = new HashMap<String, 
Object>(node.getChildren().size());
+        Map<String, Object> map =
+                new HashMap<>(node.getChildren().size());
         for (ImmutableNode cNode : node.getChildren())
         {
             if (cNode.getChildren().isEmpty())
@@ -50,10 +68,14 @@ public class AbstractMapBasedConfigurati
 
     /**
      * Constructs the internal configuration nodes hierarchy.
-     *  @param parent The configuration node that is the root of the current 
configuration section.
-     * @param map The map with the yaml configurations nodes, i.e. String -> 
Object.
+     *
+     * @param parent The configuration node that is the root of the current
+     *        configuration section.
+     * @param map The map with the yaml configurations nodes, i.e. String ->
+     *        Object.
      */
-    protected ImmutableNode constructHierarchy(ImmutableNode.Builder parent, 
Map<String, Object> map)
+    private ImmutableNode constructHierarchy(ImmutableNode.Builder parent,
+            Map<String, Object> map)
     {
         for (Map.Entry<String, Object> entry : map.entrySet())
         {
@@ -61,32 +83,32 @@ public class AbstractMapBasedConfigurati
             Object value = entry.getValue();
             if (value instanceof Map)
             {
-                ImmutableNode.Builder subtree = new ImmutableNode.Builder()
-                        .name(key);
-                ImmutableNode children = constructHierarchy(subtree, (Map) 
value);
+                ImmutableNode.Builder subtree =
+                        new ImmutableNode.Builder().name(key);
+                ImmutableNode children =
+                        constructHierarchy(subtree, (Map) value);
                 parent.addChild(children);
             }
             else
             {
-                ImmutableNode leaf = new ImmutableNode.Builder()
-                        .name(key)
-                        .value(value)
-                        .create();
+                ImmutableNode leaf = new ImmutableNode.Builder().name(key)
+                        .value(value).create();
                 parent.addChild(leaf);
             }
         }
         return parent.create();
     }
 
-
-    static void rethrowException(Exception e) throws ConfigurationException {
-        if(e instanceof ClassCastException)
+    static void rethrowException(Exception e) throws ConfigurationException
+    {
+        if (e instanceof ClassCastException)
         {
             throw new ConfigurationException("Error parsing", e);
         }
         else
         {
-            throw new ConfigurationException("Unable to load the 
configuration", e);
+            throw new ConfigurationException("Unable to load the 
configuration",
+                    e);
         }
     }
 }

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=1799502&r1=1799501&r2=1799502&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:00:35 2017
@@ -22,7 +22,6 @@ import com.fasterxml.jackson.databind.ty
 import org.apache.commons.configuration2.ex.ConfigurationException;
 import org.apache.commons.configuration2.io.InputStreamSupport;
 
-import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
@@ -35,24 +34,20 @@ import java.util.Map;
  * documents.
  * </p>
  *
- * @author  The-Alchemist
- *
- * @since commons-configuration2 2.2.?
- * @version $$
+ * @since 2.2
  */
-
-public class JSONConfiguration extends AbstractMapBasedConfiguration implements
-        FileBasedConfiguration, InputStreamSupport
+public class JSONConfiguration extends AbstractMapBasedConfiguration
+        implements FileBasedConfiguration, InputStreamSupport
 {
-
     private final ObjectMapper mapper = new ObjectMapper();
-    private final MapType type = 
mapper.getTypeFactory().constructMapType(Map.class, String.class, Object.class);
-
+    private final MapType type = mapper.getTypeFactory()
+            .constructMapType(Map.class, String.class, Object.class);
 
     /**
-     * Creates a new instance of {@code YAMLConfiguration}.
+     * Creates a new instance of {@code JSONConfiguration}.
      */
-    public JSONConfiguration() {
+    public JSONConfiguration()
+    {
         super();
     }
 
@@ -70,28 +65,13 @@ public class JSONConfiguration extends A
         }
     }
 
-    private String readFully(Reader in) {
-        try (BufferedReader r = new BufferedReader(in)) {
-            String str = null;
-            StringBuilder sb = new StringBuilder();
-            while((str =r.readLine())!=null)
-            {
-                sb.append(str);
-            }
-            return sb.toString();
-        } catch(IOException e) {
-            throw new RuntimeException(e);
-        }
-
-    }
-
     @Override
     public void write(Writer out) throws ConfigurationException, IOException
     {
-        this.mapper.writer().writeValue(out, 
constructMap(this.getNodeModel().getNodeHandler().getRootNode()));
+        this.mapper.writer().writeValue(out, constructMap(
+                this.getNodeModel().getNodeHandler().getRootNode()));
     }
 
-
     /**
      * Loads the configuration from the given input stream.
      *
@@ -112,6 +92,4 @@ public class JSONConfiguration extends A
         }
     }
 
-
-
-}
\ No newline at end of file
+}

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=1799502&r1=1799501&r2=1799502&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:00:35 2017
@@ -18,9 +18,7 @@
 package org.apache.commons.configuration2;
 
 import org.apache.commons.configuration2.ex.ConfigurationException;
-import org.apache.commons.configuration2.io.ConfigurationLogger;
 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;
@@ -29,7 +27,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
 import java.io.Writer;
-import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -38,16 +35,11 @@ import java.util.Map;
  * documents.
  * </p>
  *
- * @author  The-Alchemist
- *
- * @since commons-configuration2 2.2.?
- * @version $$
+ * @since 2.2
  */
-
-public class YAMLConfiguration extends AbstractMapBasedConfiguration implements
-        FileBasedConfiguration, InputStreamSupport
+public class YAMLConfiguration extends AbstractMapBasedConfiguration
+        implements FileBasedConfiguration, InputStreamSupport
 {
-
     /**
      * Creates a new instance of {@code YAMLConfiguration}.
      */
@@ -56,7 +48,6 @@ public class YAMLConfiguration extends A
         super();
     }
 
-
     @Override
     public void read(Reader in) throws ConfigurationException
     {
@@ -72,8 +63,8 @@ public class YAMLConfiguration extends A
         }
     }
 
-
-    public void read(Reader in, LoaderOptions options) throws 
ConfigurationException
+    public void read(Reader in, LoaderOptions options)
+            throws ConfigurationException
     {
         try
         {
@@ -95,13 +86,14 @@ public class YAMLConfiguration extends A
         dump(out, options);
     }
 
-    public void dump(Writer out, DumperOptions options) throws 
ConfigurationException, IOException
+    public void dump(Writer out, DumperOptions options)
+            throws ConfigurationException, IOException
     {
         Yaml yaml = new Yaml(options);
-        yaml.dump(constructMap(getNodeModel().getNodeHandler().getRootNode()), 
out);
+        yaml.dump(constructMap(getNodeModel().getNodeHandler().getRootNode()),
+                out);
     }
 
-
     /**
      * Loads the configuration from the given input stream.
      *
@@ -123,7 +115,8 @@ public class YAMLConfiguration extends A
         }
     }
 
-    public void read(InputStream in, LoaderOptions options) throws 
ConfigurationException
+    public void read(InputStream in, LoaderOptions options)
+            throws ConfigurationException
     {
         try
         {
@@ -137,5 +130,4 @@ public class YAMLConfiguration extends A
         }
     }
 
-
-}
\ No newline at end of file
+}

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=1799502&r1=1799501&r2=1799502&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:00:35 2017
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.commons.configuration2;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -17,14 +34,14 @@ import java.util.Map;
 import static org.junit.Assert.*;
 
 /**
- * Unit test for {@link JSONConfiguration}
- *
- * Not ideal: it uses the Jackson JSON parser just like {@link 
JSONConfiguration} itself
- * @author The-Alchemist
+ * Unit test for {@link JSONConfiguration} Not ideal: it uses the Jackson JSON
+ * parser just like {@link JSONConfiguration} itself
  */
-public class TestJSONConfiguration {
+public class TestJSONConfiguration
+{
     /** The files that we test with. */
-    private String testJson = 
ConfigurationAssert.getTestFile("test.json").getAbsolutePath();
+    private String testJson =
+            ConfigurationAssert.getTestFile("test.json").getAbsolutePath();
     private File testSaveConf = 
ConfigurationAssert.getOutFile("testsave.json");
 
     private JSONConfiguration jsonConfiguration;
@@ -52,7 +69,8 @@ public class TestJSONConfiguration {
     @Test
     public void testGetProperty_nested_with_list()
     {
-        assertEquals(Arrays.asList("col1", "col2"), 
jsonConfiguration.getProperty("key4.key5"));
+        assertEquals(Arrays.asList("col1", "col2"),
+                jsonConfiguration.getProperty("key4.key5"));
     }
 
     @Test
@@ -62,11 +80,11 @@ public class TestJSONConfiguration {
         assertEquals(Arrays.asList("col1", "col2"), 
subset.getProperty("key5"));
     }
 
-
     @Test
     public void testGetProperty_very_nested_properties()
     {
-        Object property = 
jsonConfiguration.getProperty("very.nested.properties");
+        Object property =
+                jsonConfiguration.getProperty("very.nested.properties");
         assertEquals(Arrays.asList("nested1", "nested2", "nested3"), property);
     }
 
@@ -74,12 +92,14 @@ public class TestJSONConfiguration {
     public void testGetProperty_integer()
     {
         Object property = jsonConfiguration.getProperty("int1");
-        assertTrue("property should be an Integer", property instanceof 
Integer);
+        assertTrue("property should be an Integer",
+                property instanceof Integer);
         assertEquals(37, property);
     }
 
     @Test
-    public void testSave() throws IOException, ConfigurationException {
+    public void testSave() throws IOException, ConfigurationException
+    {
         // save the Configuration as a String...
         StringWriter sw = new StringWriter();
         jsonConfiguration.write(sw);
@@ -87,7 +107,8 @@ public class TestJSONConfiguration {
 
         // ..and then try parsing it back
         ObjectMapper mapper = new ObjectMapper();
-        MapType type = mapper.getTypeFactory().constructMapType(Map.class, 
String.class, Object.class);
+        MapType type = mapper.getTypeFactory().constructMapType(Map.class,
+                String.class, Object.class);
         Map<String, Object> parsed = mapper.readValue(output, type);
         assertEquals(6, parsed.entrySet().size());
         assertEquals("value1", parsed.get("key1"));
@@ -95,7 +116,8 @@ public class TestJSONConfiguration {
         Map key2 = (Map) parsed.get("key2");
         assertEquals("value23", key2.get("key3"));
 
-        List<String> key5 = (List<String>) ((Map) 
parsed.get("key4")).get("key5");
+        List<String> key5 =
+                (List<String>) ((Map) parsed.get("key4")).get("key5");
         assertEquals(2, key5.size());
         assertEquals("col1", key5.get(0));
         assertEquals("col2", key5.get(1));
@@ -104,7 +126,8 @@ public class TestJSONConfiguration {
     @Test
     public void testGetProperty_dictionary()
     {
-        assertEquals("Martin D'vloper", 
jsonConfiguration.getProperty("martin.name"));
+        assertEquals("Martin D'vloper",
+                jsonConfiguration.getProperty("martin.name"));
         assertEquals("Developer", jsonConfiguration.getProperty("martin.job"));
         assertEquals("Elite", jsonConfiguration.getProperty("martin.skill"));
     }
@@ -120,4 +143,4 @@ public class TestJSONConfiguration {
         }
     }
 
-}
\ No newline at end of file
+}

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=1799502&r1=1799501&r2=1799502&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:00:35 2017
@@ -16,16 +16,14 @@ import java.util.Map;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-
 /**
  * Unit test for {@link YAMLConfiguration}
- *
- * @author The-Alchemist
  */
 public class TestYAMLConfiguration
 {
     /** The files that we test with. */
-    private String testYaml = 
ConfigurationAssert.getTestFile("test.yaml").getAbsolutePath();
+    private String testYaml =
+            ConfigurationAssert.getTestFile("test.yaml").getAbsolutePath();
     private File testSaveConf = 
ConfigurationAssert.getOutFile("testsave.yaml");
 
     private YAMLConfiguration yamlConfiguration;
@@ -53,7 +51,8 @@ public class TestYAMLConfiguration
     @Test
     public void testGetProperty_nested_with_list()
     {
-        assertEquals(Arrays.asList("col1", "col2"), 
yamlConfiguration.getProperty("key4.key5"));
+        assertEquals(Arrays.asList("col1", "col2"),
+                yamlConfiguration.getProperty("key4.key5"));
     }
 
     @Test
@@ -63,11 +62,11 @@ public class TestYAMLConfiguration
         assertEquals(Arrays.asList("col1", "col2"), 
subset.getProperty("key5"));
     }
 
-
     @Test
     public void testGetProperty_very_nested_properties()
     {
-        Object property = 
yamlConfiguration.getProperty("very.nested.properties");
+        Object property =
+                yamlConfiguration.getProperty("very.nested.properties");
         assertEquals(Arrays.asList("nested1", "nested2", "nested3"), property);
     }
 
@@ -75,11 +74,11 @@ public class TestYAMLConfiguration
     public void testGetProperty_integer()
     {
         Object property = yamlConfiguration.getProperty("int1");
-        assertTrue("property should be an Integer", property instanceof 
Integer);
+        assertTrue("property should be an Integer",
+                property instanceof Integer);
         assertEquals(37, property);
     }
 
-
     @Test
     public void testSave() throws IOException, ConfigurationException
     {
@@ -96,7 +95,8 @@ public class TestYAMLConfiguration
         Map key2 = (Map) parsed.get("key2");
         assertEquals("value23", key2.get("key3"));
 
-        List<String> key5 = (List<String>) ((Map) 
parsed.get("key4")).get("key5");
+        List<String> key5 =
+                (List<String>) ((Map) parsed.get("key4")).get("key5");
         assertEquals(2, key5.size());
         assertEquals("col1", key5.get(0));
         assertEquals("col2", key5.get(1));
@@ -105,7 +105,8 @@ public class TestYAMLConfiguration
     @Test
     public void testGetProperty_dictionary()
     {
-        assertEquals("Martin D'vloper", 
yamlConfiguration.getProperty("martin.name"));
+        assertEquals("Martin D'vloper",
+                yamlConfiguration.getProperty("martin.name"));
         assertEquals("Developer", yamlConfiguration.getProperty("martin.job"));
         assertEquals("Elite", yamlConfiguration.getProperty("martin.skill"));
     }


Reply via email to