Sonar cleanup 99/43399/8
authorMagnusen, Drew (dm741q) <dm741q@att.com>
Tue, 17 Apr 2018 16:59:43 +0000 (11:59 -0500)
committerPamela Dragosh <pdragosh@research.att.com>
Thu, 19 Apr 2018 18:24:06 +0000 (18:24 +0000)
More sonar cleanup. Resolved some of the simpler issues.

Issue-ID: POLICY-728
Change-Id: If9c4718f10c6d3524239d2a05c09badb791ef2f0
Signed-off-by: Magnusen, Drew (dm741q) <dm741q@att.com>
13 files changed:
feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyProperties.java
feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpEntity.java
feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpImpl.java
feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java
feature-active-standby-management/src/test/java/org/onap/policy/drools/controller/test/StandbyStateManagementTest.java
feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPDPIntegrityMonitor.java
policy-core/src/main/java/org/onap/policy/drools/util/KieUtils.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java
policy-endpoints/src/main/java/org/onap/policy/drools/http/client/HttpClientFactory.java
policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServerFactory.java
policy-endpoints/src/test/java/org/onap/policy/drools/http/server/test/HttpClientTest.java
policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureAPI.java

index 6e26334..a70c71f 100644 (file)
@@ -45,6 +45,10 @@ public class ActiveStandbyProperties {
        public static final String DB_PWD = "javax.persistence.jdbc.password";
                
        private static Properties properties = null;
+       
+       private ActiveStandbyProperties() {
+               throw new IllegalStateException("Utility class");
+       }
        /*
         * Initialize the parameter values from the droolsPersitence.properties file values
         * 
index ec1ce57..ed10f4c 100644 (file)
@@ -133,5 +133,25 @@ public class DroolsPdpEntity extends DroolsPdpObject implements Serializable{
        public void setDesignatedDate(Date designatedDate) {
                this.designatedDate = designatedDate;           
        }
+       
+       @Override
+       public boolean equals(Object obj){
+
+               if (obj instanceof DroolsPdp) {
+                       DroolsPdpEntity d = (DroolsPdpEntity) obj;
+                       return this.pdpId.equals(d.getPdpId());
+               } else {
+                       return false;
+               }
+
+       }
+       
+       @Override
+       public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + (this.pdpId == null ? 0 : this.pdpId.hashCode());
+               return result;
+       }
 
 }
index 141d585..f54a18c 100644 (file)
@@ -89,4 +89,24 @@ public class DroolsPdpImpl extends DroolsPdpObject {
                this.designatedDate = designatedDate;
                
        }
+       
+       @Override
+       public boolean equals(Object obj){
+               
+
+               if (obj instanceof DroolsPdp) {
+                       DroolsPdpImpl p = (DroolsPdpImpl) obj;
+                       return this.pdpId.equals(p.getPdpId());
+               } else {
+                       return false;
+               }
+       }
+       
+       @Override
+       public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + (this.pdpId == null ? 0 : this.pdpId.hashCode());
+               return result;
+       }
 }
index 1a09d92..9b172e1 100644 (file)
@@ -196,7 +196,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
 
                                        //It is possible that multiple PDPs are designated lead.  So, we will make a list of all designated
                                        //PDPs and then decide which one really should be designated at the end.
-                                       ArrayList<DroolsPdp> listOfDesignated = new ArrayList<>();
+                                       List<DroolsPdp> listOfDesignated = new ArrayList<>();
 
                                        Collection<DroolsPdp> pdps = pdpsConnector.getDroolsPdps();
                                        DroolsPdp designatedPdp = null;
@@ -635,11 +635,11 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
                } // end run
        }
        
-       public ArrayList<DroolsPdp> santizeDesignatedList(ArrayList<DroolsPdp> listOfDesignated){
+       public List<DroolsPdp> santizeDesignatedList(List<DroolsPdp> listOfDesignated){
 
                boolean containsDesignated = false;
                boolean containsHotStandby = false;
-               ArrayList<DroolsPdp> listForRemoval = new ArrayList<DroolsPdp>();
+               List<DroolsPdp> listForRemoval = new ArrayList<>();
                for(DroolsPdp pdp : listOfDesignated){
                        if(logger.isDebugEnabled()){
                                logger.debug
@@ -656,12 +656,11 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
                if(containsDesignated && containsHotStandby){
                        //remove the hot standby from the list
                        listOfDesignated.removeAll(listForRemoval);
-                       containsHotStandby = false;
                }
                return listOfDesignated;
        }
        
-       public DroolsPdp computeMostRecentPrimary(Collection<DroolsPdp> pdps, ArrayList<DroolsPdp> listOfDesignated){
+       public DroolsPdp computeMostRecentPrimary(Collection<DroolsPdp> pdps, List<DroolsPdp> listOfDesignated){
                boolean containsDesignated = false;
                for(DroolsPdp pdp : listOfDesignated){
                        if(pdp.isDesignated()){
index 66af3ea..0ad21f0 100644 (file)
@@ -26,8 +26,8 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 import java.util.Properties;
-
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.EntityTransaction;
@@ -321,7 +321,7 @@ public class StandbyStateManagementTest {
                DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, new Date());
                DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, new Date());
                
-               ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
+               List<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
                listOfDesignated.add(pdp1);
                listOfDesignated.add(pdp2);
                listOfDesignated.add(pdp3);
index 8fa6dfa..fb3da65 100644 (file)
@@ -186,12 +186,12 @@ class HealthCheckMonitor implements HealthCheck {
        /**
         * attached http servers
         */
-       protected volatile ArrayList<HttpServletServer> servers = new ArrayList<>();
+       protected volatile List<HttpServletServer> servers = new ArrayList<>();
        
        /**
         * attached http clients
         */
-       protected volatile ArrayList<HttpClient> clients = new ArrayList<>();
+       protected volatile List<HttpClient> clients = new ArrayList<>();
        
        /**
         * healthcheck configuration
index 46bba91..83d4f04 100644 (file)
@@ -22,6 +22,7 @@ package org.onap.policy.drools.statemanagement;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.List;
 import java.util.Properties;
 import org.onap.policy.common.im.IntegrityMonitor;
 import org.onap.policy.common.im.IntegrityMonitorException;
@@ -60,11 +61,11 @@ public class DroolsPDPIntegrityMonitor extends IntegrityMonitor
    * @param url the JMX URL of the MBean server
    * @param properties properties used locally, as well as by
    *   'IntegrityMonitor'
-   * @throws Exception (passed from superclass)
+   * @throws IntegrityMonitorException (passed from superclass)
    */
        private DroolsPDPIntegrityMonitor(String resourceName,
                        Properties consolidatedProperties
-                       ) throws Exception {
+                       ) throws IntegrityMonitorException {
        super(resourceName, consolidatedProperties);
   }
   
@@ -385,7 +386,7 @@ public class DroolsPDPIntegrityMonitor extends IntegrityMonitor
                @Override
                public boolean start() {
                        try {
-                               ArrayList<HttpServletServer> servers = HttpServletServer.factory.build(integrityMonitorRestServerProperties);
+                               List<HttpServletServer> servers = HttpServletServer.factory.build(integrityMonitorRestServerProperties);
                                
                                if (!servers.isEmpty()) {
                                        server = servers.get(0);
index 59ee511..16e166d 100644 (file)
@@ -41,6 +41,10 @@ import org.kie.scanner.MavenRepository;
  */
 public class KieUtils {
 
+       private KieUtils() {
+               throw new IllegalStateException("Utility class");
+       }
+       
     /**
      * Installs a rules artifact in the local maven repository
      *
index 88d67fd..b0c456d 100644 (file)
@@ -38,7 +38,7 @@ public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource
 
        private static Logger logger = LoggerFactory.getLogger(SingleThreadedDmaapTopicSource.class);
        
-       protected boolean allowSelfSignedCerts;
+
        protected final String userName;
        protected final String password;
        
index 06aa463..1094a2f 100644 (file)
@@ -50,7 +50,7 @@ public interface HttpClientFactory {
        /**
         * build http client from properties
         */
-       public ArrayList<HttpClient> build(Properties properties) 
+       public List<HttpClient> build(Properties properties) 
                        throws KeyManagementException, NoSuchAlgorithmException;
        
        /**
@@ -106,7 +106,7 @@ class IndexedHttpClientFactory implements HttpClientFactory {
        }
 
        @Override
-       public synchronized ArrayList<HttpClient> build(Properties properties) 
+       public synchronized List<HttpClient> build(Properties properties) 
        throws KeyManagementException, NoSuchAlgorithmException {
                ArrayList<HttpClient> clientList = new ArrayList<>();
                
index b6366d0..8c35602 100644 (file)
@@ -58,7 +58,7 @@ public interface HttpServletServerFactory {
         * @return list of http servers
         * @throws IllegalArgumentException when invalid parameters are provided
         */
-       public ArrayList<HttpServletServer> build(Properties properties) throws IllegalArgumentException;
+       public List<HttpServletServer> build(Properties properties) throws IllegalArgumentException;
        
        /**
         * gets a server based on the port
@@ -119,7 +119,7 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory {
        }
        
        @Override
-       public synchronized ArrayList<HttpServletServer> build(Properties properties) 
+       public synchronized List<HttpServletServer> build(Properties properties) 
                throws IllegalArgumentException {       
                
                ArrayList<HttpServletServer> serviceList = new ArrayList<>();
index dd9a7c2..6a84d14 100644 (file)
@@ -23,7 +23,7 @@ package org.onap.policy.drools.http.server.test;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
-import java.util.ArrayList;
+import java.util.List;
 import java.util.Properties;
 
 import javax.ws.rs.core.Response;
@@ -180,10 +180,10 @@ public class HttpClientTest {
     httpProperties.setProperty(PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP"
         + PolicyProperties.PROPERTY_MANAGED_SUFFIX, "true");
 
-    final ArrayList<HttpServletServer> servers = HttpServletServer.factory.build(httpProperties);
+    final List<HttpServletServer> servers = HttpServletServer.factory.build(httpProperties);
     assertTrue(servers.size() == 2);
 
-    final ArrayList<HttpClient> clients = HttpClient.factory.build(httpProperties);
+    final List<HttpClient> clients = HttpClient.factory.build(httpProperties);
     assertTrue(clients.size() == 2);
 
     for (final HttpServletServer server : servers) {
index dbcdb94..f415880 100644 (file)
@@ -52,5 +52,5 @@ public interface DroolsControllerFeatureAPI extends OrderedService {
           * Feature providers implementing this interface
           */
          public static final OrderedServiceImpl<DroolsControllerFeatureAPI> providers =
-                                                                       new OrderedServiceImpl<DroolsControllerFeatureAPI>(DroolsControllerFeatureAPI.class);
+                                                                       new OrderedServiceImpl<>(DroolsControllerFeatureAPI.class);
 }