Improved: Inline ‘UtilGenerics#checkCollectionContainment’

(OFBIZ-11141)


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1863493 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mathieu Lirzin
2019-07-20 16:24:39 +00:00
parent c2e2c3fb15
commit 7db8f19d08
@@ -35,10 +35,14 @@ public final class UtilGenerics {
return (V) object;
}
public static <C extends Collection<?>> void checkCollectionContainment(Object object, Class<C> clz, Class<?> type) {
public static <T> Collection<T> checkCollection(Object object) {
return cast(object);
}
public static <E, C extends Collection<E>> C checkCollection(Object object, Class<E> type) {
if (object != null) {
if (!(clz.isInstance(object))) {
throw new ClassCastException("Not a " + clz.getName());
if (!(Collection.class.isInstance(object))) {
throw new ClassCastException("Not a " + Collection.class.getName());
}
int i = 0;
for (Object value: (Collection<?>) object) {
@@ -48,14 +52,6 @@ public final class UtilGenerics {
i++;
}
}
}
public static <T> Collection<T> checkCollection(Object object) {
return cast(object);
}
public static <E, C extends Collection<E>> C checkCollection(Object object, Class<E> type) {
checkCollectionContainment(object, Collection.class, type);
return cast(object);
}