From 382eae44d29a2d0675e8a90ede650e0077d6570f Mon Sep 17 00:00:00 2001 From: sheetalm Date: Wed, 27 Dec 2017 13:47:10 +0530 Subject: Fixed sonar issues - YamlUtil Fixed violations and Added Copyright. Created constants Change-Id: I061ed453ed3706410b49774ee2bd0572a1c3a36f Issue-ID: SDC-343 Signed-off-by: sheetalm --- .../org/openecomp/sdc/tosca/services/YamlUtil.java | 40 +++++++++++++++------- 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'common/openecomp-tosca-datatype/src') 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> yamlToMap(InputStream yamlContent) { Yaml yaml = new Yaml(); - @SuppressWarnings("unchecked") Map> yamlData = - (Map>) yaml.load(yamlContent); - return yamlData; + return (Map>) yaml.load(yamlContent); } /** * Object to yaml string. - * - * @param the type parameter * @param obj the obj * @return the string */ - public 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 createPropertySet(Class type, BeanAccess bnAccess) throws IntrospectionException { - return new LinkedHashSet(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); } } -- cgit 1.2.3-korg