summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshrek2000 <orenkle@amdocs.com>2018-01-07 16:00:19 +0200
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-01-08 10:05:54 +0000
commit73efe6bbd4da6246c4e791fc7016352a539b7a1f (patch)
tree760c47e4c4b432b7bc823780df8e35be4f865d10
parent7cb0f890e1476ed6fe3832b2c422337864fb62a2 (diff)
Improve ConfigurationUtils class
Making getArrayClass more readable Issue-ID: SDC-879 Change-Id: I64d261a736056aacd5b1410a0ffa70bb8fee2eed Signed-off-by: shrek2000 <orenkle@amdocs.com>
-rw-r--r--common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/main/java/org/openecomp/config/ConfigurationUtils.java41
-rw-r--r--common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/test/java/org/openecomp/config/ConfigurationUtilsTest.java8
2 files changed, 25 insertions, 24 deletions
diff --git a/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/main/java/org/openecomp/config/ConfigurationUtils.java b/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/main/java/org/openecomp/config/ConfigurationUtils.java
index 424b5626d2..8a12d0cfcb 100644
--- a/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/main/java/org/openecomp/config/ConfigurationUtils.java
+++ b/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/main/java/org/openecomp/config/ConfigurationUtils.java
@@ -1,5 +1,6 @@
package org.openecomp.config;
+import com.google.common.collect.ImmutableMap;
import com.virtlink.commons.configuration2.jackson.JsonConfiguration;
import net.sf.corn.cps.CPScanner;
import net.sf.corn.cps.ResourceFilter;
@@ -66,6 +67,7 @@ import java.util.stream.Stream;
import static org.openecomp.config.api.Hint.EXTERNAL_LOOKUP;
import static org.openecomp.config.api.Hint.LATEST_LOOKUP;
import static org.openecomp.config.api.Hint.NODE_SPECIFIC;
+import static com.google.common.collect.ImmutableMap.*;
/**
* The type Configuration utils.
@@ -75,6 +77,17 @@ public class ConfigurationUtils {
private ConfigurationUtils() {
}
+ private static ImmutableMap<Class,Class> arrayClassMap;
+
+ static {
+ ImmutableMap.Builder<Class,Class> builder = builder();
+ builder.put(Byte.class,Byte[].class).put(Short.class, Short[].class)
+ .put(Integer.class,Integer[].class).put(Long.class,Long[].class)
+ .put(Float.class,Float[].class).put(Double.class,Double[].class)
+ .put(Boolean.class,Boolean[].class).put(Character.class,Character[].class)
+ .put(String.class,String[].class);
+ arrayClassMap = builder.build();
+ }
/**
* Gets thread factory.
@@ -119,7 +132,7 @@ public class ConfigurationUtils {
* Gets comma saperated list.
*
* @param list the list
- * @return the comma saperated list
+ * @return the comma separated list
*/
public static String getCommaSeparatedList(List list) {
return ((Stream<String>) list.stream().filter(o -> o != null && !o.toString().trim().isEmpty()).map(o -> o.toString().trim())).collect(Collectors.joining(","));
@@ -427,6 +440,8 @@ public class ConfigurationUtils {
return String[].class;
}
+
+
/**
* Gets array class.
*
@@ -434,28 +449,7 @@ public class ConfigurationUtils {
* @return the array class
*/
public static Class getArrayClass(Class clazz) {
- switch (clazz.getName()) {
- case "java.lang.Byte":
- return Byte[].class;
- case "java.lang.Short":
- return Short[].class;
- case "java.lang.Integer":
- return Integer[].class;
- case "java.lang.Long":
- return Long[].class;
- case "java.lang.Float":
- return Float[].class;
- case "java.lang.Double":
- return Double[].class;
- case "java.lang.Boolean":
- return Boolean[].class;
- case "java.lang.Character":
- return Character[].class;
- case "java.lang.String":
- return String[].class;
- default:
- return null;
- }
+ return arrayClassMap.getOrDefault(clazz, null);
}
/**
@@ -733,7 +727,6 @@ public class ConfigurationUtils {
* @return the primitive array
*/
public static Object getPrimitiveArray(Collection collection, Class clazz) {
-
if (clazz == int.class) {
int[] array = new int[collection.size()];
Object[] objArray = collection.toArray();
diff --git a/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/test/java/org/openecomp/config/ConfigurationUtilsTest.java b/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/test/java/org/openecomp/config/ConfigurationUtilsTest.java
index d6bc1f637c..b770d8677b 100644
--- a/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/test/java/org/openecomp/config/ConfigurationUtilsTest.java
+++ b/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/test/java/org/openecomp/config/ConfigurationUtilsTest.java
@@ -5,6 +5,8 @@ import org.junit.Test;
import java.util.Arrays;
import java.util.List;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class ConfigurationUtilsTest {
@@ -21,4 +23,10 @@ public class ConfigurationUtilsTest {
String commaSeparatedList = ConfigurationUtils.getCommaSeparatedList(list);
assertTrue(commaSeparatedList.isEmpty());
}
+
+ @Test
+ public void testGetArrayClassFunction() {
+ assertEquals(String[].class , ConfigurationUtils.getArrayClass(String.class));
+ assertNull(ConfigurationUtils.getArrayClass(ConfigurationUtilsTest.class));
+ }
} \ No newline at end of file