From 0da2195ac1ba608661e74dab85a753df7c619fe2 Mon Sep 17 00:00:00 2001 From: xuegao Date: Tue, 16 Jun 2020 13:15:39 +0200 Subject: Reduce nest statement levels Reduce the if/for/switch/try nest statement levels to less than 3. Issue-ID: SDC-3119 Signed-off-by: xuegao Change-Id: I60f0c0203db4495c6e10127114acdb8586867b14 Signed-off-by: xuegao --- .../org/onap/config/impl/ConfigurationImpl.java | 66 +++++++++++----------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java index 0a5a141f09..5d49fa970f 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java +++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java @@ -435,17 +435,18 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration { field.setAccessible(true); Config fieldConfAnnotation = field.getAnnotation(Config.class); Class fieldType = field.getType(); - if (fieldConfAnnotation != null) { - if (ConfigurationUtils.isAPrimitiveOrWrapper(fieldType) || - ConfigurationUtils.isAPrimitivesOrWrappersArray(fieldType)) { - setPrimitiveField(field, objToReturn, tenant, namespace, keyPrefix, hints); - } - if (ConfigurationUtils.isACollection(fieldType)) { - setCollectionField(field, objToReturn, tenant, namespace, keyPrefix, hints); - } - if (ConfigurationUtils.isAMap(fieldType)) { - setMapField(field, objToReturn, tenant, namespace, keyPrefix); - } + if (fieldConfAnnotation == null) { + continue; + } + if (ConfigurationUtils.isAPrimitiveOrWrapper(fieldType) || + ConfigurationUtils.isAPrimitivesOrWrappersArray(fieldType)) { + setPrimitiveField(field, objToReturn, tenant, namespace, keyPrefix, hints); + } + if (ConfigurationUtils.isACollection(fieldType)) { + setCollectionField(field, objToReturn, tenant, namespace, keyPrefix, hints); + } + if (ConfigurationUtils.isAMap(fieldType)) { + setMapField(field, objToReturn, tenant, namespace, keyPrefix); } } return objToReturn; @@ -471,30 +472,31 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration { Object obj = get(tenant, namespace, keyPrefix + fieldConfAnnotationKey, ConfigurationUtils.getArrayClass(ConfigurationUtils.getCollectionGenericType(field)), hints); - if (obj != null) { - List list = Arrays.asList((Object[]) obj); - Class clazzToInstantiate; - if (fieldType.isInterface()) { - clazzToInstantiate = ConfigurationUtils.getConcreteCollection(fieldType).getClass(); - } else if (Modifier.isAbstract(fieldType.getModifiers())) { - clazzToInstantiate = - ConfigurationUtils.getCompatibleCollectionForAbstractDef(fieldType) - .getClass(); - } else { - clazzToInstantiate = fieldType; - } - Constructor construct = getConstructorWithArguments(clazzToInstantiate, Collection.class); + if (obj == null) { + return; + } + List list = Arrays.asList((Object[]) obj); + Class clazzToInstantiate; + if (fieldType.isInterface()) { + clazzToInstantiate = ConfigurationUtils.getConcreteCollection(fieldType).getClass(); + } else if (Modifier.isAbstract(fieldType.getModifiers())) { + clazzToInstantiate = + ConfigurationUtils.getCompatibleCollectionForAbstractDef(fieldType) + .getClass(); + } else { + clazzToInstantiate = fieldType; + } + Constructor construct = getConstructorWithArguments(clazzToInstantiate, Collection.class); + if (construct != null) { + construct.setAccessible(true); + field.set(objToReturn, construct.newInstance(list)); + } else { + construct = getConstructorWithArguments(clazzToInstantiate, Integer.class, + Boolean.class, Collection.class); if (construct != null) { construct.setAccessible(true); - field.set(objToReturn, construct.newInstance(list)); - } else { - construct = getConstructorWithArguments(clazzToInstantiate, Integer.class, - Boolean.class, Collection.class); - if (construct != null) { - construct.setAccessible(true); - field.set(objToReturn, construct.newInstance(list.size(), true, list)); - } + field.set(objToReturn, construct.newInstance(list.size(), true, list)); } } } -- cgit 1.2.3-korg