From 9a08d687e48312beef47bce357d374ede2ce0dc7 Mon Sep 17 00:00:00 2001 From: SravanKumarGunda Date: Tue, 14 Jul 2020 14:55:47 +0530 Subject: Code Improvements Signed-off-by: SravanKumarGunda Issue-ID: CLI-270 Change-Id: I3de621dab68f153c16a36102239b095c60abf9ab --- .../java/org/onap/cli/fw/output/print/OnapCommandPrint.java | 5 +---- .../java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java | 2 +- .../java/org/onap/cli/fw/store/OnapCommandExecutionStore.java | 1 - .../java/org/onap/cli/fw/store/OnapCommandProfileStore.java | 4 +--- .../java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java | 10 ++-------- .../src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java | 6 +++--- 6 files changed, 8 insertions(+), 20 deletions(-) (limited to 'framework/src/main/java') diff --git a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java index 7a125ce5..09050c6c 100644 --- a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java +++ b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java @@ -71,10 +71,7 @@ public class OnapCommandPrint { * @return list */ public List getColumn(String header) { - if (this.data.get(header) == null) { - this.data.put(header, new ArrayList()); - } - return this.data.get(header); + return this.data.computeIfAbsent(header, k -> new ArrayList()); } public boolean isPrintTitle() { diff --git a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java index 04a81aa7..7de56025 100644 --- a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java +++ b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java @@ -511,7 +511,7 @@ public class OnapCommandSchemaLoader { * @throws OnapCommandInvalidSchema * exception */ - public static Map loadSchema(InputStream stream, String schemaName) throws OnapCommandInvalidSchema { + public static Map loadSchema(InputStream stream, String schemaName) throws OnapCommandInvalidSchema { //NOSONAR return OnapCommandDiscoveryUtils.loadYaml(stream); } diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java index 15996a8f..7352eced 100644 --- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java +++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java @@ -17,7 +17,6 @@ package org.onap.cli.fw.store; import java.io.File; -import java.io.FilenameFilter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java index 677c45ea..39645120 100644 --- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java +++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java @@ -19,7 +19,6 @@ package org.onap.cli.fw.store; import static org.onap.cli.fw.conf.OnapCommandConstants.DATA_PATH_PROFILE_JSON; import java.io.File; -import java.io.FilenameFilter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -147,8 +146,7 @@ public class OnapCommandProfileStore { } private void load(String profileName, boolean include) throws OnapCommandException { - List params= new ArrayList<>(); - params = this.loadParamFromCache(profileName); + List params = this.loadParamFromCache(profileName); for (OnapCommandParamEntity p : params) { if (include) { diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java index b2999077..b866db09 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java @@ -113,7 +113,7 @@ public class OnapCommandDiscoveryUtils { * exception */ public static List discoverOrLoadSchemas(boolean forceRefresh) throws OnapCommandException { - List schemas = new ArrayList<>(); + List schemas = new ArrayList<>(); //NOSONAR if (forceRefresh || Boolean.parseBoolean(OnapCommandConfig.getPropertyValue(OnapCommandConstants.DISCOVER_ALWAYS)) || !OnapCommandDiscoveryUtils.isAlreadyDiscovered()) { schemas = OnapCommandDiscoveryUtils.discoverSchemas(); @@ -219,13 +219,7 @@ public class OnapCommandDiscoveryUtils { * exception */ public static Map loadSchema(Resource resource) throws OnapCommandInvalidSchema { - Map values = null; - try { - values = loadYaml(resource.getInputStream()); - } catch (Exception e) { - throw new OnapCommandInvalidSchema(resource.getFilename(), e); - } - return values; + return loadYaml(resource); } /** diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java index 60bf2d2b..58fe7df6 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java @@ -328,11 +328,11 @@ public class OnapCommandUtils { || OnapCommandParameterType.JSON.equals(param.getParameterType()) || OnapCommandParameterType.YAML.equals(param.getParameterType())) { // ignore the front and back double quotes in json body - String va_ = params.get(paramName).getValue().toString(); + String value = params.get(paramName).getValue().toString(); if (idxS > 0) - result.append(line.substring(currentIdx, idxS - 1) + va_); + result.append(line.substring(currentIdx, idxS - 1) + value); else - result.append(va_); + result.append(value); currentIdx = idxE + 2; } else if (OnapCommandParameterType.MAP.equals(param.getParameterType())) { try { -- cgit 1.2.3-korg