Skip to content
Permalink
Browse files

Improved: Inline ‘UtilGenerics#checkCollectionCast’

(OFBIZ-11141)


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1863485 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Jul 20, 2019
1 parent 7b0053b commit fce71fe4e3a9acf6e41b6bb26268830e5d629171
Showing with 4 additions and 12 deletions.
  1. +4 −12 framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java
@@ -36,10 +36,6 @@ private UtilGenerics() {}
return (V) object;
}

private static <C extends Collection<?>> C checkCollectionCast(Object object, Class<C> clz) {
return clz.cast(object);
}

public static <C extends Collection<?>> void checkCollectionContainment(Object object, Class<C> clz, Class<?> type) {
if (object != null) {
if (!(clz.isInstance(object))) {
@@ -55,19 +51,17 @@ private UtilGenerics() {}
}
}

@SuppressWarnings("unchecked")
public static <T> Collection<T> checkCollection(Object object) {
return checkCollectionCast(object, Collection.class);
return cast(object);
}

public static <T> Collection<T> checkCollection(Object object, Class<T> type) {
checkCollectionContainment(object, Collection.class, type);
return checkCollection(object);
}

@SuppressWarnings("unchecked")
public static <T> List<T> checkList(Object object) {
return checkCollectionCast(object, List.class);
return cast(object);
}

public static <T> List<T> checkList(Object object, Class<T> type) {
@@ -103,19 +97,17 @@ private UtilGenerics() {}
return checkMap(object);
}

@SuppressWarnings("unchecked")
public static <T> Stack<T> checkStack(Object object) {
return checkCollectionCast(object, Stack.class);
return cast(object);
}

public static <T> Stack<T> checkStack(Object object, Class<T> type) {
checkCollectionContainment(object, Stack.class, type);
return checkStack(object);
}

@SuppressWarnings("unchecked")
public static <T> Set<T> checkSet(Object object) {
return checkCollectionCast(object, Set.class);
return cast(object);
}

public static <T> Set<T> checkSet(Object object, Class<T> type) {

0 comments on commit fce71fe

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