diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java index d087505558..cdf1991847 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java @@ -95,54 +95,6 @@ public final class UtilMisc { return col.iterator(); } - /** - * Create a map from passed nameX, valueX parameters - * @return The resulting Map - */ - public static Map toMap(String name1, V1 value1) { - return populateMap(new HashMap(), name1, value1); - } - - /** - * Create a map from passed nameX, valueX parameters - * @return The resulting Map - */ - public static Map toMap(String name1, V1 value1, String name2, V2 value2) { - return populateMap(new HashMap(), name1, value1, name2, value2); - } - - /** - * Create a map from passed nameX, valueX parameters - * @return The resulting Map - */ - public static Map toMap(String name1, V1 value1, String name2, V2 value2, String name3, V3 value3) { - return populateMap(new HashMap(), name1, value1, name2, value2, name3, value3); - } - - /** - * Create a map from passed nameX, valueX parameters - * @return The resulting Map - */ - public static Map toMap(String name1, V1 value1, String name2, V2 value2, String name3, V3 value3, String name4, V4 value4) { - return populateMap(new HashMap(), name1, value1, name2, value2, name3, value3, name4, value4); - } - - /** - * Create a map from passed nameX, valueX parameters - * @return The resulting Map - */ - public static Map toMap(String name1, V1 value1, String name2, V2 value2, String name3, V3 value3, String name4, V4 value4, String name5, V5 value5) { - return populateMap(new HashMap(), name1, value1, name2, value2, name3, value3, name4, value4, name5, value5); - } - - /** - * Create a map from passed nameX, valueX parameters - * @return The resulting Map - */ - public static Map toMap(String name1, V1 value1, String name2, V2 value2, String name3, V3 value3, String name4, V4 value4, String name5, V5 value5, String name6, V6 value6) { - return populateMap(new HashMap(), name1, value1, name2, value2, name3, value3, name4, value4, name5, value5, name6, value6); - } - /** * Create a map from passed nameX, valueX parameters * @return The resulting Map @@ -164,14 +116,6 @@ public final class UtilMisc { return map; } - @SuppressWarnings("unchecked") - private static Map populateMap(Map map, Object... data) { - for (int i = 0; i < data.length;) { - map.put((String) data[i++], (V) data[i++]); - } - return map; - } - public static String printMap(Map theMap) { StringBuilder theBuf = new StringBuilder(); for (Map.Entry entry: theMap.entrySet()) { @@ -312,90 +256,19 @@ public final class UtilMisc { } /** - * Create a Set from passed objX parameters - * @return The resulting Set + * Create a set from the passed objects. + * @param data + * @return */ - public static Set toSet(T obj1) { + @SafeVarargs + public static Set toSet(T... data) { + if (data == null) { + return null; + } Set theSet = new LinkedHashSet(); - theSet.add(obj1); - return theSet; - } - - /** - * Create a Set from passed objX parameters - * @return The resulting Set - */ - public static Set toSet(T obj1, T obj2) { - Set theSet = new LinkedHashSet(); - theSet.add(obj1); - theSet.add(obj2); - return theSet; - } - - /** - * Create a Set from passed objX parameters - * @return The resulting Set - */ - public static Set toSet(T obj1, T obj2, T obj3) { - Set theSet = new LinkedHashSet(); - theSet.add(obj1); - theSet.add(obj2); - theSet.add(obj3); - return theSet; - } - - /** - * Create a Set from passed objX parameters - * @return The resulting Set - */ - public static Set toSet(T obj1, T obj2, T obj3, T obj4) { - Set theSet = new LinkedHashSet(); - theSet.add(obj1); - theSet.add(obj2); - theSet.add(obj3); - theSet.add(obj4); - return theSet; - } - - /** - * Create a Set from passed objX parameters - * @return The resulting Set - */ - public static Set toSet(T obj1, T obj2, T obj3, T obj4, T obj5) { - Set theSet = new LinkedHashSet(); - theSet.add(obj1); - theSet.add(obj2); - theSet.add(obj3); - theSet.add(obj4); - theSet.add(obj5); - return theSet; - } - - /** - * Create a Set from passed objX parameters - * @return The resulting Set - */ - public static Set toSet(T obj1, T obj2, T obj3, T obj4, T obj5, T obj6) { - Set theSet = new LinkedHashSet(); - theSet.add(obj1); - theSet.add(obj2); - theSet.add(obj3); - theSet.add(obj4); - theSet.add(obj5); - theSet.add(obj6); - return theSet; - } - - public static Set toSet(T obj1, T obj2, T obj3, T obj4, T obj5, T obj6, T obj7, T obj8) { - Set theSet = new LinkedHashSet(); - theSet.add(obj1); - theSet.add(obj2); - theSet.add(obj3); - theSet.add(obj4); - theSet.add(obj5); - theSet.add(obj6); - theSet.add(obj7); - theSet.add(obj8); + for (T elem : data) { + theSet.add(elem); + } return theSet; } @@ -420,100 +293,24 @@ public final class UtilMisc { } return set; } - - /** - * Create a list from passed objX parameters - * @return The resulting List - */ - public static List toList(T obj1) { - List list = new LinkedList(); - - list.add(obj1); - return list; - } - - /** - * Create a list from passed objX parameters - * @return The resulting List - */ - public static List toList(T obj1, T obj2) { - List list = new LinkedList(); - - list.add(obj1); - list.add(obj2); - return list; - } - - /** - * Create a list from passed objX parameters - * @return The resulting List - */ - public static List toList(T obj1, T obj2, T obj3) { - List list = new LinkedList(); - - list.add(obj1); - list.add(obj2); - list.add(obj3); - return list; - } - - /** - * Create a list from passed objX parameters - * @return The resulting List - */ - public static List toList(T obj1, T obj2, T obj3, T obj4) { - List list = new LinkedList(); - - list.add(obj1); - list.add(obj2); - list.add(obj3); - list.add(obj4); - return list; - } - - /** - * Create a list from passed objX parameters - * @return The resulting List - */ - public static List toList(T obj1, T obj2, T obj3, T obj4, T obj5) { - List list = new LinkedList(); - - list.add(obj1); - list.add(obj2); - list.add(obj3); - list.add(obj4); - list.add(obj5); - return list; - } - - /** - * Create a list from passed objX parameters - * @return The resulting List - */ - public static List toList(T obj1, T obj2, T obj3, T obj4, T obj5, T obj6) { - List list = new LinkedList(); - - list.add(obj1); - list.add(obj2); - list.add(obj3); - list.add(obj4); - list.add(obj5); - list.add(obj6); - return list; - } - public static List toList(T obj1, T obj2, T obj3, T obj4, T obj5, T obj6, T obj7, T obj8, T obj9) { + /** + * Creates a list from passed objects. + * @param data + * @return + */ + @SafeVarargs + public static List toList(T... data) { + if(data == null){ + return null; + } + List list = new LinkedList(); - list.add(obj1); - list.add(obj2); - list.add(obj3); - list.add(obj4); - list.add(obj5); - list.add(obj6); - list.add(obj7); - list.add(obj8); - list.add(obj9); + for(T t : data){ + list.add(t); + } + return list; }