@Test public void shouldBuildSets() { Set<String> expectedSet = new HashSet<>(asList("one", "nine", "three")); assertEquals(expectedSet, TypeHelper.toSet(expectedSet, String.class.getName(), String.class.getClassLoader())); List<String> regularCollection = asList("one", "nine", "three"); assertEquals(expectedSet, TypeHelper.toSet(regularCollection, String.class.getName(), String.class.getClassLoader())); List<Map<String, String>> listOfMapsFromUI = asList(mapFromUI("one"), mapFromUI("nine"), mapFromUI("three")); assertEquals(expectedSet, TypeHelper.toSet(listOfMapsFromUI, String.class.getName(), String.class.getClassLoader())); assertEquals(expectedSet, TypeHelper.toSet("one,nine,three", String.class.getName(), String.class.getClassLoader())); }
public static Set toSet(Object object, String typeClass, ClassLoader classLoader) { if (object instanceof Set) { return (Set) object; } else if (object instanceof Collection) { Set set = new HashSet(); Collection collection = (Collection) object; for (Object collMember : collection) { Object value = null; if (collMember instanceof Map) { Map map = (Map) collMember; if (map.containsKey("val")) { value = map.get("val"); } } else { value = collMember; } if (value != null) { set.add(parse(value, typeClass, classLoader)); } } return set; } else if (object instanceof String) { String[] values = StringUtils.split((String) object, ','); return toSet(Arrays.asList(values), typeClass, classLoader); } else { throw unableToParseException(object, Set.class); } }
TypeHelper { public static Set toSet(Object object, String typeClass, ClassLoader classLoader) { if (object instanceof Set) { return (Set) object; } else if (object instanceof Collection) { Set set = new HashSet(); Collection collection = (Collection) object; for (Object collMember : collection) { Object value = null; if (collMember instanceof Map) { Map map = (Map) collMember; if (map.containsKey("val")) { value = map.get("val"); } } else { value = collMember; } if (value != null) { set.add(parse(value, typeClass, classLoader)); } } return set; } else if (object instanceof String) { String[] values = StringUtils.split((String) object, ','); return toSet(Arrays.asList(values), typeClass, classLoader); } else { throw unableToParseException(object, Set.class); } } }
TypeHelper { public static Set toSet(Object object, String typeClass, ClassLoader classLoader) { if (object instanceof Set) { return (Set) object; } else if (object instanceof Collection) { Set set = new HashSet(); Collection collection = (Collection) object; for (Object collMember : collection) { Object value = null; if (collMember instanceof Map) { Map map = (Map) collMember; if (map.containsKey("val")) { value = map.get("val"); } } else { value = collMember; } if (value != null) { set.add(parse(value, typeClass, classLoader)); } } return set; } else if (object instanceof String) { String[] values = StringUtils.split((String) object, ','); return toSet(Arrays.asList(values), typeClass, classLoader); } else { throw unableToParseException(object, Set.class); } } private  TypeHelper(); }
TypeHelper { public static Set toSet(Object object, String typeClass, ClassLoader classLoader) { if (object instanceof Set) { return (Set) object; } else if (object instanceof Collection) { Set set = new HashSet(); Collection collection = (Collection) object; for (Object collMember : collection) { Object value = null; if (collMember instanceof Map) { Map map = (Map) collMember; if (map.containsKey("val")) { value = map.get("val"); } } else { value = collMember; } if (value != null) { set.add(parse(value, typeClass, classLoader)); } } return set; } else if (object instanceof String) { String[] values = StringUtils.split((String) object, ','); return toSet(Arrays.asList(values), typeClass, classLoader); } else { throw unableToParseException(object, Set.class); } } private  TypeHelper(); static Object parse(Object val, Class<?> toClass); static Object parse(Object val, String toClass); static Object parse(Object val, String toClass, ClassLoader classLoader); static Object parse(Object val, String toClass, String genericType); static Object parse(Object val, String toClass, String genericType, ClassLoader classLoader); static Object parseString(String str, Class<?> toClass); static Object parseString(String str, String toClass); static Object parseString(String str, Class<?> toClass, Class<?> generic); static String buildStringFromList(List<String> items); static String[] breakString(String str); static String[] breakStringForCollection(String str); static String[] breakString(String str, String[] removes, String[] search,
                                       String[] replacement, String separator); static Map parseStringToMap(String str); static Map<K, V> parseStringToMap(Class<K> keyClass, Class<V> valueClass, String str); static Map parseStringToMap(String keyClass, String valueClass, String str); static Object parseStringToUUID(String val); static Object parseMapValue(Object valueToParse, String type, boolean isKey); static boolean isTypeSupportedInMap(String type, boolean isKey); static Object parseDateToDate(Object val, String toClass); static Collection parseCollection(Collection val, Class<?> toClassDefinition, Class<?> generic); static boolean parseIntToBool(Integer val); static String format(Object obj); static String format(Object obj, char collJoinChar); static Number parseNumber(Object val, String toClass); static boolean hasPrimitive(Class<?> clazz); static boolean isPrimitive(Class<?> clazz); static boolean isPrimitive(String className); static Class<?> getPrimitive(Class<?> clazz); static Class<?> getWrapperForPrimitive(Class<?> clazz); static String getClassNameForMdsType(Class<?> clazz); static Range toRange(Object object, String typeClass); static Set toSet(Object object, String typeClass, ClassLoader classLoader); static Class suggestCollectionImplementation(String collectionClass); static Class<? extends Collection> suggestCollectionImplementation(Class<? extends Collection> collectionClass); static Collection suggestAndCreateCollectionImplementation(Class<? extends Collection> collectionClass); static Collection<T> asCollection(Object value); static boolean isBaseEntity(String entitySuperClass); static boolean isSubclassOfMdsEntity(String entitySuperClass); static boolean isSubclassOfMdsVersionedEntity(String entitySuperClass); }
TypeHelper { public static Set toSet(Object object, String typeClass, ClassLoader classLoader) { if (object instanceof Set) { return (Set) object; } else if (object instanceof Collection) { Set set = new HashSet(); Collection collection = (Collection) object; for (Object collMember : collection) { Object value = null; if (collMember instanceof Map) { Map map = (Map) collMember; if (map.containsKey("val")) { value = map.get("val"); } } else { value = collMember; } if (value != null) { set.add(parse(value, typeClass, classLoader)); } } return set; } else if (object instanceof String) { String[] values = StringUtils.split((String) object, ','); return toSet(Arrays.asList(values), typeClass, classLoader); } else { throw unableToParseException(object, Set.class); } } private  TypeHelper(); static Object parse(Object val, Class<?> toClass); static Object parse(Object val, String toClass); static Object parse(Object val, String toClass, ClassLoader classLoader); static Object parse(Object val, String toClass, String genericType); static Object parse(Object val, String toClass, String genericType, ClassLoader classLoader); static Object parseString(String str, Class<?> toClass); static Object parseString(String str, String toClass); static Object parseString(String str, Class<?> toClass, Class<?> generic); static String buildStringFromList(List<String> items); static String[] breakString(String str); static String[] breakStringForCollection(String str); static String[] breakString(String str, String[] removes, String[] search,
                                       String[] replacement, String separator); static Map parseStringToMap(String str); static Map<K, V> parseStringToMap(Class<K> keyClass, Class<V> valueClass, String str); static Map parseStringToMap(String keyClass, String valueClass, String str); static Object parseStringToUUID(String val); static Object parseMapValue(Object valueToParse, String type, boolean isKey); static boolean isTypeSupportedInMap(String type, boolean isKey); static Object parseDateToDate(Object val, String toClass); static Collection parseCollection(Collection val, Class<?> toClassDefinition, Class<?> generic); static boolean parseIntToBool(Integer val); static String format(Object obj); static String format(Object obj, char collJoinChar); static Number parseNumber(Object val, String toClass); static boolean hasPrimitive(Class<?> clazz); static boolean isPrimitive(Class<?> clazz); static boolean isPrimitive(String className); static Class<?> getPrimitive(Class<?> clazz); static Class<?> getWrapperForPrimitive(Class<?> clazz); static String getClassNameForMdsType(Class<?> clazz); static Range toRange(Object object, String typeClass); static Set toSet(Object object, String typeClass, ClassLoader classLoader); static Class suggestCollectionImplementation(String collectionClass); static Class<? extends Collection> suggestCollectionImplementation(Class<? extends Collection> collectionClass); static Collection suggestAndCreateCollectionImplementation(Class<? extends Collection> collectionClass); static Collection<T> asCollection(Object value); static boolean isBaseEntity(String entitySuperClass); static boolean isSubclassOfMdsEntity(String entitySuperClass); static boolean isSubclassOfMdsVersionedEntity(String entitySuperClass);  }