Fix checkstyle/sonar issues 39/74139/2
authorliamfallon <liam.fallon@est.tech>
Mon, 3 Dec 2018 14:35:21 +0000 (14:35 +0000)
committerliamfallon <liam.fallon@est.tech>
Mon, 3 Dec 2018 14:41:52 +0000 (14:41 +0000)
Remove unused imports
Add @FunctionalInterface annotation
Reduce the complexity of some methods

Change-Id: If519c31b113233361fbb935121fe6494263ac957
Issue-ID: POLICY-1074
Signed-off-by: liamfallon <liam.fallon@est.tech>
core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageListener.java
examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java
services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java
testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/java/DefaultTaskLogic.java
testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/java/EvalTaskLogic.java
testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/testsuites/performance/context/metrics/ConcurrentContextMetrics.java
tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Model2JsonEventSchema.java

index d60b04c..32387d0 100644 (file)
@@ -119,17 +119,7 @@ public class AutoLearnPolicyDecideTaskSelectionLogic {
                 closestdowni = i;
             }
         }
-        if (closestupi == -1 || closestdowni == -1) {
-            return r;
-        }
-        if (closestupi == closestdowni) {
-            return closestupi;
-        }
-        if (Math.abs(closestdown - diff) > Math.abs(closestup - diff)) {
-            return closestupi;
-        } else {
-            return closestdowni;
-        }
+        return calculateReturnValue(diff, r, closestupi, closestdowni, closestup, closestdown);
     }
 
     /**
@@ -154,4 +144,30 @@ public class AutoLearnPolicyDecideTaskSelectionLogic {
         autoLearn.setAvDiffs(Arrays.asList(avdiffs));
         autoLearn.setCounts(Arrays.asList(counts));
     }
+    
+
+    /**
+     * Calculate the return value of the learning
+     * @param diff the difference
+     * @param r the random value
+     * @param closestupi closest to i upwards
+     * @param closestdowni closest to i downwards
+     * @param closestup closest up value
+     * @param closestdown closest down value
+     * @return the return value
+     */
+    private int calculateReturnValue(final double diff, final int r, int closestupi, int closestdowni, double closestup,
+                    double closestdown) {
+        if (closestupi == -1 || closestdowni == -1) {
+            return r;
+        }
+        if (closestupi == closestdowni) {
+            return closestupi;
+        }
+        if (Math.abs(closestdown - diff) > Math.abs(closestup - diff)) {
+            return closestupi;
+        } else {
+            return closestdowni;
+        }
+    }
 }
index c39be64..08c0e69 100644 (file)
@@ -127,30 +127,7 @@ public class ApexActivator {
                 unmarshaller.init(engineServiceHandler);
             }
 
-            // Set up unmarshaler/marshaler pairing for synchronized event handling. We only need to
-            // traverse the unmarshalers because the
-            // unmarshalers and marshalers are paired one to one uniquely so if we find a
-            // synchronized unmarshaler we'll also find its
-            // paired marshaler
-            for (final Entry<String, EventHandlerParameters> inputParameters : apexParameters.getEventInputParameters()
-                    .entrySet()) {
-                final ApexEventUnmarshaller unmarshaller = unmarshallerMap.get(inputParameters.getKey());
-
-                // Pair up peered unmarshalers and marshalers
-                for (final EventHandlerPeeredMode peeredMode : EventHandlerPeeredMode.values()) {
-                    // Check if the unmarshaler is synchronized with a marshaler
-                    if (inputParameters.getValue().isPeeredMode(peeredMode)) {
-                        // Find the unmarshaler and marshaler
-                        final ApexEventMarshaller peeredMarshaler =
-                                marshallerMap.get(inputParameters.getValue().getPeer(peeredMode));
-
-                        // Connect the unmarshaler and marshaler
-                        unmarshaller.connectMarshaler(peeredMode, peeredMarshaler);
-                    }
-                }
-                // Now let's get events flowing
-                unmarshaller.start();
-            }
+            setUpmarshalerPairings();
         } catch (final Exception e) {
             LOGGER.debug("Apex engine failed to start as a service", e);
             throw new ApexActivatorException("Apex engine failed to start as a service", e);
@@ -159,6 +136,35 @@ public class ApexActivator {
         LOGGER.debug("Apex engine started as a service");
     }
 
+    /**
+     * Set up unmarshaler/marshaler pairing for synchronized event handling. We only need to
+     * traverse the unmarshalers because the
+     * unmarshalers and marshalers are paired one to one uniquely so if we find a
+     * synchronized unmarshaler we'll also find its
+     * paired marshaler
+     */
+    private void setUpmarshalerPairings() {
+        for (final Entry<String, EventHandlerParameters> inputParameters : apexParameters.getEventInputParameters()
+                .entrySet()) {
+            final ApexEventUnmarshaller unmarshaller = unmarshallerMap.get(inputParameters.getKey());
+
+            // Pair up peered unmarshalers and marshalers
+            for (final EventHandlerPeeredMode peeredMode : EventHandlerPeeredMode.values()) {
+                // Check if the unmarshaler is synchronized with a marshaler
+                if (inputParameters.getValue().isPeeredMode(peeredMode)) {
+                    // Find the unmarshaler and marshaler
+                    final ApexEventMarshaller peeredMarshaler =
+                            marshallerMap.get(inputParameters.getValue().getPeer(peeredMode));
+
+                    // Connect the unmarshaler and marshaler
+                    unmarshaller.connectMarshaler(peeredMode, peeredMarshaler);
+                }
+            }
+            // Now let's get events flowing
+            unmarshaller.start();
+        }
+    }
+
     /**
      * Terminate the Apex engine.
      *
index 08ad008..e860da7 100644 (file)
@@ -23,7 +23,6 @@ package org.onap.policy.apex.testsuites.integration.common.model.java;
 import java.util.Random;
 
 import org.onap.policy.apex.core.engine.executor.context.TaskExecutionContext;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
 
 /**
  * The Class DefaultTask_Logic is default task logic in Java.
index c4e4de4..b0bfb1c 100644 (file)
@@ -72,39 +72,6 @@ public class ConcurrentContextMetrics {
     private final File zookeeperDirectory;
     private final int zookeeperPort;
 
-    /**
-     * The main method.
-     *
-     * @param args the args
-     * @throws Exception the exception
-     */
-    public static void main(final String[] args) throws Exception {
-        if (args.length != NUM_ARGS) {
-            String errorMessage = "Args: " + Arrays.toString(args)
-                            + "\nusage: testLabel jvmCount threadCount threadLoops longArraySize lockType "
-                            + "zookeeperAddress zookeeperPort zookeeperDirectory";
-            LOGGER.info(errorMessage);
-            return;
-        }
-
-        final ConfigrationProvider configrationProvider = new ConfigrationProviderImpl(args[ARG_LABEL],
-                        Integer.valueOf(args[ARG_JVM_COUNT]), Integer.valueOf(args[ARG_THREAD_COUNT]),
-                        Integer.valueOf(args[ARG_ITERATIONS]), Integer.valueOf(args[ARG_ARRAY_SIZE]),
-                        Integer.valueOf(args[ARG_LOCK_TYPE]));
-
-        final ConcurrentContextMetrics concurrentContextMetrics = new ConcurrentContextMetrics(configrationProvider,
-                        args[ARG_ZOOKEEPER_ADDRESS], Integer.valueOf(args[ARG_ZOOKEEPER_PORT]),
-                        args[ARG_ZOOKEEPER_DIRECTORY]);
-
-        concurrentContextMetrics.concurrentContextMetricsJvmLocal();
-        concurrentContextMetrics.concurrentContextMetricsCurator();
-        concurrentContextMetrics.concurrentContextMetricsHazelcast();
-        concurrentContextMetrics.concurrentContextMetricsHazelcastMultiJvmHazelcastLock();
-        concurrentContextMetrics.concurrentContextMetricsInfinispanMultiJvmHazelcastlock();
-        concurrentContextMetrics.concurrentContextMetricsInfinispanMultiJvmCuratorLock();
-        concurrentContextMetrics.concurrentContextMetricsHazelcastMultiJvmCuratorLock();
-    }
-
     /**
      * Construct a concurrent context object.
      * 
@@ -128,7 +95,7 @@ public class ConcurrentContextMetrics {
      * @throws IOException the IO exception
      * @throws ApexException the apex exception
      */
-    private void concurrentContextMetricsJvmLocal() throws IOException, ApexException {
+    private void concurrentContextMetricsJvmLocal() throws ApexException {
         if (configrationProvider.getJvmCount() != 1) {
             return;
         }
@@ -149,7 +116,7 @@ public class ConcurrentContextMetrics {
      * @throws IOException the IO exception
      * @throws ApexException the apex exception
      */
-    private void concurrentContextMetricsHazelcast() throws IOException, ApexException {
+    private void concurrentContextMetricsHazelcast() throws ApexException {
         if (configrationProvider.getJvmCount() != 1) {
             return;
         }
@@ -170,7 +137,7 @@ public class ConcurrentContextMetrics {
      * @throws IOException the IO exception
      * @throws ApexException the apex exception
      */
-    private void concurrentContextMetricsCurator() throws IOException, ApexException {
+    private void concurrentContextMetricsCurator() throws ApexException {
         if (configrationProvider.getJvmCount() != 1) {
             return;
         }
@@ -196,7 +163,7 @@ public class ConcurrentContextMetrics {
      * @throws IOException the IO exception
      * @throws ApexException the apex exception
      */
-    private void concurrentContextMetricsHazelcastMultiJvmHazelcastLock() throws IOException, ApexException {
+    private void concurrentContextMetricsHazelcastMultiJvmHazelcastLock() throws ApexException {
         LOGGER.debug("Running concurrentContextMetricsHazelcastMultiJVMHazelcastLock metrics . . .");
 
         final ContextParameters contextParameters = new ContextParameters();
@@ -214,7 +181,7 @@ public class ConcurrentContextMetrics {
      * @throws IOException the IO exception
      * @throws ApexException the apex exception
      */
-    private void concurrentContextMetricsInfinispanMultiJvmHazelcastlock() throws IOException, ApexException {
+    private void concurrentContextMetricsInfinispanMultiJvmHazelcastlock() throws ApexException {
         LOGGER.debug("Running concurrentContextMetricsInfinispanMultiJVMHazelcastlock metrics . . .");
 
         final ContextParameters contextParameters = new ContextParameters();
@@ -238,7 +205,7 @@ public class ConcurrentContextMetrics {
      * @throws InterruptedException on interrupts
      */
     private void concurrentContextMetricsInfinispanMultiJvmCuratorLock()
-                    throws IOException, ApexException, InterruptedException {
+                    throws ApexException {
 
         LOGGER.debug("Running concurrentContextMetricsInfinispanMultiJVMCuratorLock metrics . . .");
 
@@ -273,7 +240,7 @@ public class ConcurrentContextMetrics {
      * @throws InterruptedException on interrupts
      */
     private void concurrentContextMetricsHazelcastMultiJvmCuratorLock()
-                    throws IOException, ApexException, InterruptedException {
+                    throws ApexException {
         LOGGER.debug("Running concurrentContextMetricsHazelcastMultiJVMCuratorLock metrics . . .");
 
         final ZooKeeperServerServiceProvider zooKeeperServerServiceProvider = new ZooKeeperServerServiceProvider(
@@ -304,7 +271,7 @@ public class ConcurrentContextMetrics {
      * @throws IOException the IO exception
      * @throws ApexException the apex exception
      */
-    private void runConcurrentContextMetrics(final String testName) throws IOException, ApexException {
+    private void runConcurrentContextMetrics(final String testName) throws ApexException {
         final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider);
 
         LOGGER.info("Running {} ...", testName);
@@ -320,4 +287,36 @@ public class ConcurrentContextMetrics {
         LOGGER.info("Completed {} ...", testName);
     }
 
+    /**
+     * The main method.
+     *
+     * @param args the args
+     * @throws Exception the exception
+     */
+    public static void main(final String[] args) throws Exception {
+        if (args.length != NUM_ARGS) {
+            String errorMessage = "Args: " + Arrays.toString(args)
+                            + "\nusage: testLabel jvmCount threadCount threadLoops longArraySize lockType "
+                            + "zookeeperAddress zookeeperPort zookeeperDirectory";
+            LOGGER.info(errorMessage);
+            return;
+        }
+
+        final ConfigrationProvider configrationProvider = new ConfigrationProviderImpl(args[ARG_LABEL],
+                        Integer.valueOf(args[ARG_JVM_COUNT]), Integer.valueOf(args[ARG_THREAD_COUNT]),
+                        Integer.valueOf(args[ARG_ITERATIONS]), Integer.valueOf(args[ARG_ARRAY_SIZE]),
+                        Integer.valueOf(args[ARG_LOCK_TYPE]));
+
+        final ConcurrentContextMetrics concurrentContextMetrics = new ConcurrentContextMetrics(configrationProvider,
+                        args[ARG_ZOOKEEPER_ADDRESS], Integer.valueOf(args[ARG_ZOOKEEPER_PORT]),
+                        args[ARG_ZOOKEEPER_DIRECTORY]);
+
+        concurrentContextMetrics.concurrentContextMetricsJvmLocal();
+        concurrentContextMetrics.concurrentContextMetricsCurator();
+        concurrentContextMetrics.concurrentContextMetricsHazelcast();
+        concurrentContextMetrics.concurrentContextMetricsHazelcastMultiJvmHazelcastLock();
+        concurrentContextMetrics.concurrentContextMetricsInfinispanMultiJvmHazelcastlock();
+        concurrentContextMetrics.concurrentContextMetricsInfinispanMultiJvmCuratorLock();
+        concurrentContextMetrics.concurrentContextMetricsHazelcastMultiJvmCuratorLock();
+    }
 }
index 86a826b..9041a80 100644 (file)
@@ -150,13 +150,11 @@ public class Model2JsonEventSchema {
             case FLOAT:
             case INT:
             case LONG:
-            case STRING: {
+            case STRING:
                 return true;
-            }
             
-            default: {
+            default:
                 return false;
-            }
         }
     }