From 8a894e564dc7577d78273c890396ffb5dbe86bbb Mon Sep 17 00:00:00 2001 From: "michal.banka" Date: Tue, 16 Jul 2019 13:51:00 +0200 Subject: Fix checkstyle violations in sdc-main/common Change-Id: I3e132cf4bffd77f9910bf6eff2026c3267873b11 Issue-ID: SDC-2454 Signed-off-by: michal.banka --- .../java/org/onap/config/ConfigurationUtils.java | 13 +++++++------ .../java/org/onap/config/impl/ConfigurationImpl.java | 20 ++++++++++++-------- .../onap/config/impl/ConfigurationRepository.java | 18 +++++++++--------- 3 files changed, 28 insertions(+), 23 deletions(-) (limited to 'common/onap-common-configuration-management/onap-configuration-management-core') diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java index b18649181d..991ec5fc8b 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java +++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java @@ -433,12 +433,13 @@ public class ConfigurationUtils { Pattern pattern = Pattern.compile("^.*\\$\\{(.*)\\}.*"); Matcher matcher = pattern.matcher(data); if (matcher.matches()) { + final int substringStartIndex = 4; String key = matcher.group(1); String value; if (key.toUpperCase().startsWith("ENV:")) { - value = System.getenv(key.substring(4)); + value = System.getenv(key.substring(substringStartIndex)); } else if (key.toUpperCase().startsWith("SYS:")) { - value = System.getProperty(key.substring(4)); + value = System.getProperty(key.substring(substringStartIndex)); } else { value = ConfigurationUtils.getCollectionString( ConfigurationManager.lookup().getAsStringValues(tenant, namespace, key).toString()); @@ -513,8 +514,8 @@ public class ConfigurationUtils { if (List.class.isAssignableFrom(clazz)) { return getConcreteCollection(List.class); } - throw new IllegalArgumentException("Only corresponding array classes and any are allowed as argument." + - "assignable from TransferQueue, BlockingQueue, Deque, Queue, SortedSet, Set, List class"); + throw new IllegalArgumentException("Only corresponding array classes and any are allowed as argument." + + "assignable from TransferQueue, BlockingQueue, Deque, Queue, SortedSet, Set, List class"); } public static Collection getConcreteCollection(Class clazz) { @@ -535,8 +536,8 @@ public class ConfigurationUtils { case "java.util.concurrent.BlockingQueue": return new LinkedBlockingQueue<>(); default: - throw new IllegalArgumentException("Only corresponding array classes and any are allowed as argument." + - "assignable from TransferQueue, BlockingQueue, Deque, Queue, SortedSet, Set, List class"); + throw new IllegalArgumentException("Only corresponding array classes and any are allowed as argument." + + "assignable from TransferQueue, BlockingQueue, Deque, Queue, SortedSet, Set, List class"); } } 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 6cad62ef03..9a3fbd26fb 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 @@ -44,7 +44,7 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration { private static final String KEY_CANNOT_BE_NULL = "Key can't be null."; - private static final NonConfigResource nonConfigResource = new NonConfigResource(); + private static final NonConfigResource NON_CONFIG_RESOURCE = new NonConfigResource(); static { @@ -70,7 +70,7 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration { } moduleConfig.addConfig(url); } else { - nonConfigResource.add(url); + NON_CONFIG_RESOURCE.add(url); } } String configLocation = System.getProperty("config.location"); @@ -88,7 +88,7 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration { } moduleConfig.addConfig(file); } else { - nonConfigResource.add(file); + NON_CONFIG_RESOURCE.add(file); } } } @@ -397,13 +397,17 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration { clazzToInstantiate = field.getType(); } Constructor construct = getConstructorWithArguments(clazzToInstantiate, Collection.class); + if (construct != null) { construct.setAccessible(true); field.set(objToReturn, construct.newInstance(list)); - } else if ((construct = getConstructorWithArguments(clazzToInstantiate, Integer.class, - Boolean.class, Collection.class)) != null) { - construct.setAccessible(true); - field.set(objToReturn, construct.newInstance(list.size(), true, 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)); + } } } } else if (Map.class.isAssignableFrom(field.getType())) { @@ -454,7 +458,7 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration { if (String.class.equals(clazz)) { if (obj.toString().startsWith("@") && ConfigurationUtils.isExternalLookup(processingHint)) { String contents = ConfigurationUtils.getFileContents( - nonConfigResource.locate(obj.toString().substring(1).trim())); + NON_CONFIG_RESOURCE.locate(obj.toString().substring(1).trim())); if (contents == null) { contents = ConfigurationUtils.getFileContents(obj.toString().substring(1).trim()); } diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationRepository.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationRepository.java index 5863caef68..63c3b7563f 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationRepository.java +++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationRepository.java @@ -35,7 +35,7 @@ import org.onap.config.Constants; public final class ConfigurationRepository { - private static final ConfigurationRepository repo = new ConfigurationRepository(); + private static final ConfigurationRepository REPO = new ConfigurationRepository(); private final Set tenants = Collections.synchronizedSet(new HashSet<>()); @@ -63,7 +63,7 @@ public final class ConfigurationRepository { } public static ConfigurationRepository lookup() { - return repo; + return REPO; } public Set getTenants() { @@ -119,20 +119,20 @@ public final class ConfigurationRepository { private final Map> overrideConfiguration = new LinkedHashMap<>(); - BasicConfigurationBuilder builder; - Timestamp lastConfigurationBuildTime; - Configuration config; - Configuration composite; + private BasicConfigurationBuilder builder; + private Timestamp lastConfigurationBuildTime; + private Configuration config; + private Configuration composite; - public ConfigurationHolder(BasicConfigurationBuilder builder) { + ConfigurationHolder(BasicConfigurationBuilder builder) { this.builder = builder; } - public ConfigurationHolder(Configuration builder) { + ConfigurationHolder(Configuration builder) { this.config = builder; } - public void addOverrideConfiguration(String path, BasicConfigurationBuilder builder) { + void addOverrideConfiguration(String path, BasicConfigurationBuilder builder) { overrideConfiguration.put(path.toUpperCase(), (FileBasedConfigurationBuilder) builder); getEffectiveConfiguration(config, overrideConfiguration.values()); } -- cgit 1.2.3-korg