From 9104eb39d56848952e68d660bdc3cc7500789501 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Mon, 3 Dec 2018 14:35:21 +0000 Subject: Fix checkstyle/sonar issues Remove unused imports Add @FunctionalInterface annotation Reduce the complexity of some methods Change-Id: If519c31b113233361fbb935121fe6494263ac957 Issue-ID: POLICY-1074 Signed-off-by: liamfallon --- .../AutoLearnPolicyDecideTaskSelectionLogic.java | 38 +++++++++++++++------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'examples/examples-adaptive/src/main/java') diff --git a/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java b/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java index d60b04c00..32387d047 100644 --- a/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java +++ b/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java @@ -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; + } + } } -- cgit 1.2.3-korg