@Test public void nullCheckCollection() { assertNull(UtilGenerics.<String, Collection<String>>checkCollection(null, String.class)); }
public static <E, C extends Collection<E>> C checkCollection(Object object, Class<E> type) { if (object != null) { if (!(Collection.class.isInstance(object))) { throw new ClassCastException("Not a " + Collection.class.getName()); } int i = 0; for (Object value: (Collection<?>) object) { if (value != null && !type.isInstance(value)) { throw new IllegalArgumentException("Value(" + i + "), with value(" + value + ") is not a " + type.getName()); } i++; } } return cast(object); }
UtilGenerics { public static <E, C extends Collection<E>> C checkCollection(Object object, Class<E> type) { if (object != null) { if (!(Collection.class.isInstance(object))) { throw new ClassCastException("Not a " + Collection.class.getName()); } int i = 0; for (Object value: (Collection<?>) object) { if (value != null && !type.isInstance(value)) { throw new IllegalArgumentException("Value(" + i + "), with value(" + value + ") is not a " + type.getName()); } i++; } } return cast(object); } }
UtilGenerics { public static <E, C extends Collection<E>> C checkCollection(Object object, Class<E> type) { if (object != null) { if (!(Collection.class.isInstance(object))) { throw new ClassCastException("Not a " + Collection.class.getName()); } int i = 0; for (Object value: (Collection<?>) object) { if (value != null && !type.isInstance(value)) { throw new IllegalArgumentException("Value(" + i + "), with value(" + value + ") is not a " + type.getName()); } i++; } } return cast(object); } private  UtilGenerics(); }
UtilGenerics { public static <E, C extends Collection<E>> C checkCollection(Object object, Class<E> type) { if (object != null) { if (!(Collection.class.isInstance(object))) { throw new ClassCastException("Not a " + Collection.class.getName()); } int i = 0; for (Object value: (Collection<?>) object) { if (value != null && !type.isInstance(value)) { throw new IllegalArgumentException("Value(" + i + "), with value(" + value + ") is not a " + type.getName()); } i++; } } return cast(object); } private  UtilGenerics(); @SuppressWarnings("unchecked") static V cast(Object object); static C checkCollection(Object object, Class<E> type); static Map<K, V> checkMap(Object object, Class<K> keyType, Class<V> valueType); }
UtilGenerics { public static <E, C extends Collection<E>> C checkCollection(Object object, Class<E> type) { if (object != null) { if (!(Collection.class.isInstance(object))) { throw new ClassCastException("Not a " + Collection.class.getName()); } int i = 0; for (Object value: (Collection<?>) object) { if (value != null && !type.isInstance(value)) { throw new IllegalArgumentException("Value(" + i + "), with value(" + value + ") is not a " + type.getName()); } i++; } } return cast(object); } private  UtilGenerics(); @SuppressWarnings("unchecked") static V cast(Object object); static C checkCollection(Object object, Class<E> type); static Map<K, V> checkMap(Object object, Class<K> keyType, Class<V> valueType);  }