diff options
author | liamfallon <liam.fallon@est.tech> | 2018-12-03 14:35:21 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2018-12-03 14:41:52 +0000 |
commit | 9104eb39d56848952e68d660bdc3cc7500789501 (patch) | |
tree | 66ac25de7e95dfbc9ab9b3f0b1a41a57bb18d48f /examples | |
parent | fb7c89ebe2e682170b09275a5e531d0a49d70ada (diff) |
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 <liam.fallon@est.tech>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java | 38 |
1 files changed, 27 insertions, 11 deletions
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; + } + } } |