aboutsummaryrefslogtreecommitdiffstats
path: root/common/onap-common-configuration-management/onap-configuration-management-core
diff options
context:
space:
mode:
authorDejan Kitic <dejan.kitic@ericsson.com>2018-05-02 10:29:04 +0100
committerOren Kleks <orenkle@amdocs.com>2018-05-06 06:04:04 +0000
commitafe48b5d270ad0716e7e2398e036aabe56987e11 (patch)
treef5deebbcf86b679ad44937c5863265d46dbdeac6 /common/onap-common-configuration-management/onap-configuration-management-core
parentb13e94fffca6e4feae95ea9523bed785b8057c93 (diff)
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 <dejan.kitic@ericsson.com>
Diffstat (limited to 'common/onap-common-configuration-management/onap-configuration-management-core')
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java55
1 files changed, 19 insertions, 36 deletions
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<FileBasedConfiguration> getConfigurationBuilder(URL url) {
- ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration> builder = null;
ConfigurationType configType = ConfigurationUtils.getConfigType(url);
- switch (configType) {
- case PROPERTIES:
- builder = new ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration>(
- PropertiesConfiguration.class);
- break;
- case XML:
- builder = new ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration>(
- XMLConfiguration.class);
- break;
- case JSON:
- builder = new ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration>(
- JsonConfiguration.class);
- break;
- case YAML:
- builder = new ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration>(
- YamlConfiguration.class);
- break;
- default:
- throw new IllegalArgumentException("Configuration type not supported:"+ configType);
- }
+ ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration> 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<FileBasedConfiguration> getConfigurationBuilder(File file,
boolean autoSave) {
- ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration> builder = null;
+ ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration> 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<FileBasedConfiguration> getFileBasedConfigurationReloadingFileBasedConfigurationBuilder(
+ ConfigurationType configType) {
+ ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration> builder;
switch (configType) {
case PROPERTIES:
- builder = new ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration>(
- PropertiesConfiguration.class);
+ builder = new ReloadingFileBasedConfigurationBuilder<>(PropertiesConfiguration.class);
break;
case XML:
- builder = new ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration>(
- XMLConfiguration.class);
+ builder = new ReloadingFileBasedConfigurationBuilder<>(XMLConfiguration.class);
break;
case JSON:
- builder = new ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration>(
- JsonConfiguration.class);
+ builder = new ReloadingFileBasedConfigurationBuilder<>(JsonConfiguration.class);
break;
case YAML:
- builder = new ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration>(
- 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<String> 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());
}
/**