summaryrefslogtreecommitdiffstats
path: root/common/openecomp-tosca-datatype
diff options
context:
space:
mode:
authorsheetalm <sheetal.mudholkar@amdocs.com>2017-12-27 13:47:10 +0530
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2017-12-27 14:45:23 +0000
commit382eae44d29a2d0675e8a90ede650e0077d6570f (patch)
treecd9d6006889f2777f640a2079ec4140e4c6f84ea /common/openecomp-tosca-datatype
parent5acfbc6eb741836a63cd75ebc2dfc60c2ff1bc5a (diff)
Fixed sonar issues - YamlUtil
Fixed violations and Added Copyright. Created constants Change-Id: I061ed453ed3706410b49774ee2bd0572a1c3a36f Issue-ID: SDC-343 Signed-off-by: sheetalm <sheetal.mudholkar@amdocs.com>
Diffstat (limited to 'common/openecomp-tosca-datatype')
-rw-r--r--common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/services/YamlUtil.java40
1 files changed, 28 insertions, 12 deletions
diff --git a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/services/YamlUtil.java b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/services/YamlUtil.java
index 755f02a4f8..3d7715a8db 100644
--- a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/services/YamlUtil.java
+++ b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/services/YamlUtil.java
@@ -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);
}
}