From 72c2d38329865afa6692454b4fb90ab6f8a70638 Mon Sep 17 00:00:00 2001 From: Joanna Jeremicz Date: Thu, 25 Feb 2021 15:24:34 +0100 Subject: Fix sonar issues - Use Map instead of LinkedHashMap when possible - Rename some constants - Remove some commented lines - Add logger - Other minor improvements and refactor Issue-ID: DCAEGEN2-2636 Signed-off-by: Joanna Jeremicz Change-Id: I7a03cee453b3d254c4ff0fdf51c60a0ae4a61c42 --- .../service/base/FixesService.java | 61 ++++++++++++---------- 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/FixesService.java') diff --git a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/FixesService.java b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/FixesService.java index 4c6debc..961528b 100644 --- a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/FixesService.java +++ b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/FixesService.java @@ -4,6 +4,7 @@ * * org.onap.dcae * * ================================================================================ * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * Copyright (c) 2021 Nokia. All rights reserved. * * ================================================================================ * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. @@ -55,15 +56,15 @@ public class FixesService { FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); for (String line = br.readLine(); line != null; line = br.readLine()) { - if (line.contains("'")) { - line = processLine(line); + String newLine = line; + if (newLine.contains("'")) { + newLine = processLine(newLine); } - if (line.contains("get_input") || line.contains("get_secret") || line + if (newLine.contains("get_input") || newLine.contains("get_secret") || newLine .contains("envs")) { - line = line.replaceAll("'", ""); + newLine = newLine.replace("'", ""); } - - lines.add(line); + lines.add(newLine); } fr.close(); @@ -90,8 +91,8 @@ public class FixesService { * @return */ public String fixStringQuotes(String string) { - String sLines[] = string.split("\n"); - String ret = ""; + String[] sLines = string.split("\n"); + StringBuilder ret = new StringBuilder(); for (String line : sLines) { if (line.contains("get_input") || line.contains("get_secret") @@ -101,15 +102,16 @@ public class FixesService { || line.contains("dmaap") || line.contains(".\"'")) && line.contains("'"))) { - line = line.replaceAll("'", ""); + line = line.replace("'", ""); } if (line.contains("'")) { line = processLine(line); } - ret = ret + "\n" + line; + ret.append("\n"); + ret.append(line); } - return ret; + return ret.toString(); } /** @@ -124,13 +126,14 @@ public class FixesService { FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); for (String line = br.readLine(); line != null; line = br.readLine()) { - if (line.contains("'")) { - line = line.replace("'", ""); + String newLine = line; + if (newLine.contains("'")) { + newLine = newLine.replace("'", ""); } - if (line.contains("\"\"") && (line.contains("m") || line.contains("M"))) { - line = line.replaceAll("\"\"", "\""); + if (newLine.contains("\"\"") && (newLine.contains("m") || newLine.contains("M"))) { + newLine = newLine.replace("\"\"", "\""); } - lines.add(line); + lines.add(newLine); } fr.close(); br.close(); @@ -185,18 +188,18 @@ public class FixesService { } private String processLine(String line) { - return line.replaceAll("'\\{", "{") - .replaceAll("}'", "}") - .replaceAll("'\\[", "[") - .replaceAll("]'", "]") - .replaceAll("'''''", "'") - .replaceAll("'''", "'") - .replaceAll("'''", "") - .replaceAll("''\\{", "'{") - .replaceAll("}''", "}'") - .replaceAll("''\\[", "'[") - .replaceAll("]''", "]'") - .replaceAll("\"''", "'") - .replaceAll("''\"", "'"); + return line.replace("'\\{", "{") + .replace("}'", "}") + .replace("'\\[", "[") + .replace("]'", "]") + .replace("'''''", "'") + .replace("'''", "'") + .replace("'''", "") + .replace("''\\{", "'{") + .replace("}''", "}'") + .replace("''\\[", "'[") + .replace("]''", "]'") + .replace("\"''", "'") + .replace("''\"", "'"); } } -- cgit 1.2.3-korg