Fix Fortify Log Forging Issue
[policy/engine.git] / PolicyEngineAPI / src / main / java / org / onap / policy / std / MatchStore.java
index a243c1f..e5204d8 100644 (file)
@@ -22,22 +22,24 @@ package org.onap.policy.std;
 
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.Set;
 
 import org.onap.policy.api.LoadedPolicy;
 import org.onap.policy.api.NotificationType;
 import org.onap.policy.api.PDPNotification;
 import org.onap.policy.api.RemovedPolicy;
-import org.onap.policy.std.StdLoadedPolicy;
-import org.onap.policy.std.StdPDPNotification;
-import org.onap.policy.std.StdRemovedPolicy;
-
-import org.onap.policy.common.logging.flexlogger.*; 
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger; 
 
 public class MatchStore {
        private static HashSet<Matches> matchStore = new HashSet<>();
        private static Logger logger = FlexLogger.getLogger(MatchStore.class.getName());
        
-       public static HashSet<Matches> getMatchStore() {
+       private MatchStore() {
+               // Empty Constructor
+       }
+       
+       public static Set<Matches> getMatchStore() {
                return matchStore;
        }
 
@@ -94,7 +96,7 @@ public class MatchStore {
                                        
                                }
                                // IF not a match then add it to the MatchStore
-                               if(match==false){
+                               if(! match){
                                        matchStore.add(newMatch);
                                }
                        }
@@ -103,14 +105,14 @@ public class MatchStore {
        
        //Logic changes for Requested Policies notifications.. 
        public static PDPNotification checkMatch(PDPNotification oldNotification) {
-               boolean removed = false, updated = false;
+               boolean removed = false;
+               boolean updated = false;
                if(oldNotification==null){
                        return null;
                }
                StdPDPNotification newNotification = new StdPDPNotification();
                if(matchStore.isEmpty()) {
                        logger.debug("No Success Config Calls made yet.. ");
-                       System.out.println("No success Config calls made yet. ");
                        return null;
                } 
                if(oldNotification.getRemovedPolicies()!=null && !oldNotification.getRemovedPolicies().isEmpty()){
@@ -132,7 +134,7 @@ public class MatchStore {
                        for(LoadedPolicy updatedPolicy: oldNotification.getLoadedPolicies()){
                                // if it is config policies check their matches..
                                if(updatedPolicy.getMatches()!=null && !updatedPolicy.getMatches().isEmpty()){
-                                       boolean matched = false;
+                                       boolean matched;
                                        for(Matches match : matchStore){
                                                matched = false;
                                                // Again Better way would be comparing sizes first.
@@ -144,14 +146,14 @@ public class MatchStore {
                                                                // Comparing both the values.. 
                                                                boolean matchAttributes = false;
                                                                for(String newKey: updatedPolicy.getMatches().keySet()){
-                                                                       if(newKey.equals("ONAPName")){
+                                                                       if("ONAPName".equals(newKey)){
                                                                                if(updatedPolicy.getMatches().get(newKey).equals(match.getOnapName())){
                                                                                        matchAttributes = true;
                                                                                }else {
                                                                                        matchAttributes = false;
                                                                                        break;
                                                                                }
-                                                                       }else if(newKey.equals("ConfigName")) {
+                                                                       }else if("ConfigName".equals(newKey)) {
                                                                                if(updatedPolicy.getMatches().get(newKey).equals(match.getConfigName())){
                                                                                        matchAttributes = true;
                                                                                }else{