From f13efdabda4ff77eedccf5595616c9423710f405 Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Wed, 30 Aug 2017 05:48:57 -0700 Subject: Fix Sonar bugs In OperationalPolicyReq.class Blocker issues fixed Change-Id: If35ab7674961c6d9c7558b1f81d7fd5fb22eae45 Issue-Id: CLAMP-43 Signed-off-by: Determe, Sebastien (sd378r) --- .../clds/client/req/OperationalPolicyReq.java | 39 ++++++++-------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java b/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java index 950fcefe5..e7f956d33 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java +++ b/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java @@ -23,6 +23,12 @@ package org.onap.clamp.clds.client.req; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFLogger.Level; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; @@ -31,7 +37,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.jboss.resteasy.spi.BadRequestException; +import javax.ws.rs.BadRequestException; + import org.onap.clamp.clds.model.prop.Global; import org.onap.clamp.clds.model.prop.ModelProperties; import org.onap.clamp.clds.model.prop.PolicyChain; @@ -52,12 +59,6 @@ import org.onap.policy.controlloop.policy.builder.ControlLoopPolicyBuilder; import org.onap.policy.controlloop.policy.builder.Message; import org.onap.policy.controlloop.policy.builder.Results; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFLogger.Level; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - /** * Construct an Operational Policy request given CLDS objects. */ @@ -426,16 +427,10 @@ public class OperationalPolicyReq { * @return */ private static Resource[] convertToResource(List stringList, ResourceType resourceType) { - int size = 0; - if (stringList != null) { - size = stringList.size(); - } - Resource[] resourceArray = new Resource[size]; - for (int i = 0; i < size; i++) { - String rString = stringList.get(i); - resourceArray[i] = new Resource(rString, resourceType); + if (stringList == null || stringList.isEmpty()) { + return new Resource[0]; } - return resourceArray; + return stringList.stream().map(stringElem -> new Resource(stringElem, resourceType)).toArray(Resource[]::new); } /** @@ -446,16 +441,10 @@ public class OperationalPolicyReq { * @return */ private static PolicyResult[] convertToPolicyResult(List prList) { - int size = 0; - if (prList != null) { - size = prList.size(); - } - PolicyResult[] prArray = new PolicyResult[size]; - for (int i = 0; i < size; i++) { - String prString = prList.get(i); - prArray[i] = PolicyResult.toResult(prString); + if (prList == null || prList.isEmpty()) { + return new PolicyResult[0]; } - return prArray; + return prList.stream().map(stringElem -> PolicyResult.toResult(stringElem)).toArray(PolicyResult[]::new); } } \ No newline at end of file -- cgit 1.2.3-korg