Fixed sonar issues - ComponentDependencyTracker 87/27087/2
authormojahidi <mojahidul.islam@amdocs.com>
Thu, 28 Dec 2017 12:07:41 +0000 (17:37 +0530)
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>
Sun, 31 Dec 2017 08:50:29 +0000 (08:50 +0000)
Fixed all sonar issues

Change-Id: I6a6ab4217964a8071af86e090570f8cb4a8dc122
Issue-ID: SDC-343
Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/utils/ComponentDependencyTracker.java

index a31558f..39f04d6 100644 (file)
@@ -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.vendorsoftwareproduct.utils;
 
 import java.util.HashMap;
@@ -6,7 +22,7 @@ import java.util.Map;
 import java.util.Set;
 
 public class ComponentDependencyTracker {
-  Map<String, Set<String>> store = new HashMap<>();
+  private final Map<String, Set<String>> store = new HashMap<>();
 
   /**
    * Add dependency.
@@ -17,14 +33,9 @@ public class ComponentDependencyTracker {
   public void addDependency(String dependent, String dependsOn) {
     if (dependent != null && dependsOn != null && dependent.trim().length() > 0 && dependsOn.trim()
         .length() > 0) {
-      dependent = dependent.toLowerCase();
-      dependsOn = dependsOn.toLowerCase();
-      Set<String> dependsOnList = store.get(dependent);
-      if (dependsOnList == null) {
-        dependsOnList = new HashSet<>();
-        store.put(dependent, dependsOnList);
-      }
-      dependsOnList.add(dependsOn);
+      Set<String> dependsOnList = store
+              .computeIfAbsent(dependent.toLowerCase(), k -> new HashSet<>());
+      dependsOnList.add(dependsOn.toLowerCase());
     }
   }