Fixed sonar issues - YamlUtil 79/26879/4
authorsheetalm <sheetal.mudholkar@amdocs.com>
Wed, 27 Dec 2017 08:17:10 +0000 (13:47 +0530)
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>
Wed, 27 Dec 2017 14:45:23 +0000 (14:45 +0000)
Fixed violations and Added Copyright. Created constants

Change-Id: I061ed453ed3706410b49774ee2bd0572a1c3a36f
Issue-ID: SDC-343
Signed-off-by: sheetalm <sheetal.mudholkar@amdocs.com>
common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/services/YamlUtil.java

index 755f02a..3d7715a 100644 (file)
@@ -1,3 +1,19 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * Licensed 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.openecomp.sdc.tosca.services;
 
 import org.yaml.snakeyaml.DumperOptions;
@@ -28,6 +44,9 @@ import java.util.Set;
 @SuppressWarnings("unchecked")
 public class YamlUtil {
 
+  private static final String DEFAULT = "default";
+  private static final String DEFAULT_STR = "_default";
+
   /**
    * Yaml to object t.
    *
@@ -118,19 +137,15 @@ public class YamlUtil {
    */
   public Map<String, LinkedHashMap<String, Object>> yamlToMap(InputStream yamlContent) {
     Yaml yaml = new Yaml();
-    @SuppressWarnings("unchecked") Map<String, LinkedHashMap<String, Object>> yamlData =
-        (Map<String, LinkedHashMap<String, Object>>) yaml.load(yamlContent);
-    return yamlData;
+    return (Map<String, LinkedHashMap<String, Object>>) yaml.load(yamlContent);
   }
 
   /**
    * Object to yaml string.
-   *
-   * @param <T> the type parameter
    * @param obj the obj
    * @return the string
    */
-  public <T> String objectToYaml(Object obj) {
+  public String objectToYaml(Object obj) {
     DumperOptions options = new DumperOptions();
     options.setPrettyFlow(true);
     options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
@@ -179,8 +194,8 @@ public class YamlUtil {
         NodeTuple defaultNode =
             super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
 
-        return property.getName().equals("_default")
-            ? new NodeTuple(representData("default"), defaultNode.getValueNode())
+        return DEFAULT_STR.equals(property.getName())
+            ? new NodeTuple(representData(DEFAULT), defaultNode.getValueNode())
             : defaultNode;
       }
     }
@@ -195,16 +210,17 @@ public class YamlUtil {
     @Override
     protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess bnAccess)
         throws IntrospectionException {
-      return new LinkedHashSet<Property>(getPropertiesMap(type,
+      return new LinkedHashSet<>(getPropertiesMap(type,
           BeanAccess.FIELD).values());
     }
 
     @Override
     public Property getProperty(Class<?> type, String name) throws IntrospectionException {
-      if (name.equals("default")) {
-        name = "_default";
+      String updatedName = name;
+      if (DEFAULT.equals(updatedName)) {
+        updatedName = DEFAULT_STR;
       }
-      return super.getProperty(type, name);
+      return super.getProperty(type, updatedName);
     }
 
   }