aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxuegao <xg353y@intl.att.com>2020-06-16 13:15:39 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-06-17 13:02:48 +0000
commit0da2195ac1ba608661e74dab85a753df7c619fe2 (patch)
treeec84a74f2612957c3010566a11c5c98a48ce74b8
parent5971be1a797d4ad232257c4bf5dd8c3359b56ede (diff)
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 <xg353y@intl.att.com> Change-Id: I60f0c0203db4495c6e10127114acdb8586867b14 Signed-off-by: xuegao <xg353y@intl.att.com>
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java66
1 files 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<Object> 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<Object> 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));
}
}
}