Skip to content
Permalink
Browse files

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
  • Loading branch information
mthl committed Jul 20, 2019
1 parent c2e2c3f commit 7db8f19d08d48b13f168baf871f6f09e5131a35c
Showing with 7 additions and 11 deletions.
  1. +7 −11 framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java
@@ -35,10 +35,14 @@ private 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 @@ private 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);
}

0 comments on commit 7db8f19

Please sign in to comment.
You can’t perform that action at this time.