private static Class<?> getCollectionType(Collection collection) throws Exception { if (collection == null || collection.isEmpty()) { return null; } Object targetObject = CollectionUtil.getItemAtPositionOrNull(collection, 0); if (targetObject == null) { for (Object object : collection) { if (object != null) { return object.getClass(); } } return null; } return targetObject.getClass(); }
private static Class<?> getCollectionType(Collection collection) throws Exception { if (collection == null || collection.isEmpty()) { return null; } Object targetObject = CollectionUtil.getItemAtPositionOrNull(collection, 0); if (targetObject == null) { for (Object object : collection) { if (object != null) { return object.getClass(); } } return null; } return targetObject.getClass(); }
private Object getItemAtPositionOrNull(Object object, int position) { if (object == null) { return null; } else if (object instanceof Collection) { return CollectionUtil.getItemAtPositionOrNull((Collection) object, position); } else if (object instanceof Object[]) { return ArrayUtils.getItemAtPositionOrNull((Object[]) object, position); } else if (object.getClass().isArray()) { return Array.get(object, position); } throw new IllegalArgumentException("Cannot extract an element from class of type" + object.getClass() + " Collections and Arrays are supported only"); }
private Object getItemAtPositionOrNull(Object object, int position) { if (object == null) { return null; } else if (object instanceof Collection) { return CollectionUtil.getItemAtPositionOrNull((Collection) object, position); } else if (object instanceof Object[]) { return ArrayUtils.getItemAtPositionOrNull((Object[]) object, position); } else if (object.getClass().isArray()) { return Array.get(object, position); } throw new IllegalArgumentException("Cannot extract an element from class of type" + object.getClass() + " Collections and Arrays are supported only"); }