Fix sonar issues
[dcaegen2/platform.git] / mod / bpgenerator / common / src / main / java / org / onap / blueprintgenerator / service / base / FixesService.java
index 4c6debc..961528b 100644 (file)
@@ -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("''\"", "'");
     }
 }