Skip to content

Commit

Permalink
Improved: Inline ‘UtilGenerics#checkCollectionCast’
Browse files Browse the repository at this point in the history
(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 fce71fe
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public static <V> V cast(Object object) {
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))) {
Expand All @@ -55,19 +51,17 @@ public static <C extends Collection<?>> void checkCollectionContainment(Object o
}
}

@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) {
Expand Down Expand Up @@ -103,19 +97,17 @@ public static <K, V> Map<K, V> checkMap(Object object, Class<K> keyType, Class<V
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) {
Expand Down

0 comments on commit fce71fe

Please sign in to comment.