Fixing sonar bugs in apex-pdp 05/57805/1
authorramverma <ram.krishna.verma@ericsson.com>
Fri, 27 Jul 2018 09:40:01 +0000 (10:40 +0100)
committerramverma <ram.krishna.verma@ericsson.com>
Fri, 27 Jul 2018 09:41:24 +0000 (10:41 +0100)
Sonar was complaining about direct comparision of double values. Changed
the comparision to Double.compare(d1,d2).

Change-Id: I3821924e606180626434d5bc41e29b9a8451a9b2
Issue-ID: POLICY-861
Signed-off-by: ramverma <ram.krishna.verma@ericsson.com>
examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AnomalyDetectionPolicy_Decide_TaskSelectionLogic.java

index a0b2a8f..a044ad1 100644 (file)
@@ -230,7 +230,7 @@ public class AnomalyDetectionPolicy_Decide_TaskSelectionLogic {
         while (pValue < significanceLevel) { // takes approx 20% of method time
             // the score value as the anomaly probability
             final double score = (significanceLevel - pValue) / significanceLevel;
-            if (v == currentV) {
+            if (Double.compare(v, currentV) == 0) {
                 return score;
             }
             // do the critical check again for the left values
@@ -326,7 +326,7 @@ public class AnomalyDetectionPolicy_Decide_TaskSelectionLogic {
      */
     private static Double[] removevalue(final Double[] lValues, final double v) {
         for (int i = 0; i < lValues.length; i++) {
-            if (lValues[i] == v) {
+            if (Double.compare(lValues[i], v) == 0) {
                 final Double[] ret = new Double[lValues.length - 1];
                 System.arraycopy(lValues, 0, ret, 0, i);
                 System.arraycopy(lValues, i + 1, ret, i, lValues.length - i - 1);
@@ -389,7 +389,7 @@ public class AnomalyDetectionPolicy_Decide_TaskSelectionLogic {
     private static boolean isAllEqual(final List<Double> lValues) {
         final double first = lValues.get(0);
         for (final Double d : lValues) {
-            if (d != first) {
+            if (Double.compare(d, first) != 0) {
                 return false;
             }
         }
@@ -405,7 +405,7 @@ public class AnomalyDetectionPolicy_Decide_TaskSelectionLogic {
     private static boolean isAllEqual(final Double[] lValues) {
         final double first = lValues[0];
         for (final Double d : lValues) {
-            if (d != first) {
+            if (Double.compare(d, first) != 0) {
                 return false;
             }
         }