From afe48b5d270ad0716e7e2398e036aabe56987e11 Mon Sep 17 00:00:00 2001 From: Dejan Kitic Date: Wed, 2 May 2018 10:29:04 +0100 Subject: This patch removes first chunk of duplicated code Removing some of the duplicated code, and few minor code simplifications. Keeping the original file formatting to make review easier, will update the patch and reformat the file to comply with ONAP java code requirements Issue-ID: SDC-1270 Change-Id: I3f6393a19197754bcb860957b0db87100a8ac893 Signed-off-by: dekstroza --- .../java/org/onap/config/ConfigurationUtils.java | 55 ++++++++-------------- 1 file changed, 19 insertions(+), 36 deletions(-) (limited to 'common/onap-common-configuration-management/onap-configuration-management-core/src/main') 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 7f22461cda..358dab923f 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 @@ -491,28 +491,9 @@ public class ConfigurationUtils { * @return the configuration builder */ public static BasicConfigurationBuilder getConfigurationBuilder(URL url) { - ReloadingFileBasedConfigurationBuilder builder = null; ConfigurationType configType = ConfigurationUtils.getConfigType(url); - switch (configType) { - case PROPERTIES: - builder = new ReloadingFileBasedConfigurationBuilder( - PropertiesConfiguration.class); - break; - case XML: - builder = new ReloadingFileBasedConfigurationBuilder( - XMLConfiguration.class); - break; - case JSON: - builder = new ReloadingFileBasedConfigurationBuilder( - JsonConfiguration.class); - break; - case YAML: - builder = new ReloadingFileBasedConfigurationBuilder( - YamlConfiguration.class); - break; - default: - throw new IllegalArgumentException("Configuration type not supported:"+ configType); - } + ReloadingFileBasedConfigurationBuilder builder = getFileBasedConfigurationReloadingFileBasedConfigurationBuilder( + configType); builder.configure(new Parameters().fileBased().setURL(url) .setListDelimiterHandler(new DefaultListDelimiterHandler(','))); return builder; @@ -527,31 +508,34 @@ public class ConfigurationUtils { */ public static BasicConfigurationBuilder getConfigurationBuilder(File file, boolean autoSave) { - ReloadingFileBasedConfigurationBuilder builder = null; + ReloadingFileBasedConfigurationBuilder builder; ConfigurationType configType = ConfigurationUtils.getConfigType(file); + builder = getFileBasedConfigurationReloadingFileBasedConfigurationBuilder(configType); + builder.configure(new Parameters().fileBased().setFile(file) + .setListDelimiterHandler(new DefaultListDelimiterHandler(','))); + builder.setAutoSave(autoSave); + return builder; + } + + private static ReloadingFileBasedConfigurationBuilder getFileBasedConfigurationReloadingFileBasedConfigurationBuilder( + ConfigurationType configType) { + ReloadingFileBasedConfigurationBuilder builder; switch (configType) { case PROPERTIES: - builder = new ReloadingFileBasedConfigurationBuilder( - PropertiesConfiguration.class); + builder = new ReloadingFileBasedConfigurationBuilder<>(PropertiesConfiguration.class); break; case XML: - builder = new ReloadingFileBasedConfigurationBuilder( - XMLConfiguration.class); + builder = new ReloadingFileBasedConfigurationBuilder<>(XMLConfiguration.class); break; case JSON: - builder = new ReloadingFileBasedConfigurationBuilder( - JsonConfiguration.class); + builder = new ReloadingFileBasedConfigurationBuilder<>(JsonConfiguration.class); break; case YAML: - builder = new ReloadingFileBasedConfigurationBuilder( - YamlConfiguration.class); + builder = new ReloadingFileBasedConfigurationBuilder<>(YamlConfiguration.class); break; default: throw new IllegalArgumentException("Configuration type not supported:"+ configType); } - builder.configure(new Parameters().fileBased().setFile(file) - .setListDelimiterHandler(new DefaultListDelimiterHandler(','))); - builder.setAutoSave(autoSave); return builder; } @@ -599,7 +583,6 @@ public class ConfigurationUtils { * @throws Exception the exception */ public static boolean executeInsertSql(String sql, Object[] params) throws Exception { - Collection coll = new ArrayList<>(); DataSource datasource = ConfigurationDataSource.lookup(); try (Connection con = datasource.getConnection(); PreparedStatement stmt = con.prepareStatement(sql)) { @@ -941,7 +924,7 @@ public class ConfigurationUtils { } else if (boolean.class == clazz) { return Boolean.FALSE; } - return new Character((char) 0); + return (char) 0; } /** @@ -1075,7 +1058,7 @@ public class ConfigurationUtils { Object obj = ConfigurationUtils .getProperty(ConfigurationRepository.lookup().getConfigurationFor(tenant, namespace), key, processingHints); - return (obj == null) ? false : ConfigurationUtils.isCollection(obj.toString()); + return (obj != null) && ConfigurationUtils.isCollection(obj.toString()); } /** -- cgit 1.2.3-korg