summaryrefslogtreecommitdiffstats
path: root/appc-dispatcher
diff options
context:
space:
mode:
authorTomek Kaminski <tomasz.kaminski@nokia.com>2018-01-03 13:13:09 +0100
committerSkip Wonnell <skip@att.com>2018-01-03 15:59:07 +0000
commit7ed69b1e3f118f0fb19efecf46607c0debb2ea82 (patch)
treea3997d7fcb589195532e78edffea4b2460f43800 /appc-dispatcher
parent4c07c938e34afea7128e0fafa0c43e5a5331a3c5 (diff)
Fix sonar blockers
Fix two blockers with possible NPE in accessing parentNode Fix major related to using diamond operator with generics Fix major related to nesting more than 3 if statements. Change-Id: Ic3e5271bc599120ff6a3d1f74c97e614866c44ad Issue-ID: APPC-367 Signed-off-by: Tomek Kaminski <tomasz.kaminski@nokia.com>
Diffstat (limited to 'appc-dispatcher')
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/RankedAttributesTreeBuilder.java22
1 files changed, 10 insertions, 12 deletions
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/RankedAttributesTreeBuilder.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/RankedAttributesTreeBuilder.java
index 2a7cfbfe0..9092a1361 100644
--- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/RankedAttributesTreeBuilder.java
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/RankedAttributesTreeBuilder.java
@@ -45,9 +45,7 @@ class RankedAttributesTreeBuilder {
CompositeNode<R> root = new CompositeNode<>("ROOT", Constants.DEFAULT_MATCH, null,
new HashMap<Object, Node<R>>());
- if (logger.isDebugEnabled()) {
- logger.debug(String.format("Building decision tree for ranked attributes: %s", config.getRankedAttributeNames()));
- }
+ logDebugWhenEnabled(String.format("Building decision tree for ranked attributes: %s", config.getRankedAttributeNames()));
for (ConfigurationEntry<R> entry : config.getEntries()) {
process(entry, names, root);
@@ -57,13 +55,9 @@ class RankedAttributesTreeBuilder {
}
private static <R> void process(ConfigurationEntry<R> entry, Object[] names, CompositeNode<R> root) {
- CompositeNode<R> parentNode = null;
+ CompositeNode<R> parentNode = root;
for (int i = 0; i < names.length; i++) {
- if (i == 0) {
- parentNode = root;
- }
-
final String name = (String) names[i];
final Object value = value(entry, name);
@@ -78,12 +72,10 @@ class RankedAttributesTreeBuilder {
} else {
LeafNode<R> currentNode = (LeafNode<R>) parentNode.children().get(value);
if (currentNode == null) {
- currentNode = new LeafNode<R>(name, value, parentNode, entry.getResult());
+ currentNode = new LeafNode<>(name, value, parentNode, entry.getResult());
parentNode.children().put(value, currentNode);
- if (logger.isDebugEnabled()) {
- logger.debug(String.format("Branch has been created: %s", currentNode));
- }
+ logDebugWhenEnabled(String.format("Branch has been created: %s", currentNode));
} else {
logger.error(
String.format("Duplicated configuration entry has been detected for attribute '%s' with value '%s' - the node '%s'exists already",
@@ -96,6 +88,12 @@ class RankedAttributesTreeBuilder {
}
}
+ private static void logDebugWhenEnabled(String message) {
+ if(logger.isDebugEnabled()) {
+ logger.debug(message);
+ }
+ }
+
private static <R> Object value(ConfigurationEntry<R> entry, String name) {
Object value = entry.getAttributeValue(name);
return Utils.value(value);