/** * Find a single value of one of the given types in the given Collection: * searching the Collection for a value of the first type, then * searching for a value of the second type, etc. * * @param collection the collection to search * @param types the types to look for, in prioritized order * @return a value of one of the given types found if there is a clear match, * or <code>null</code> if none or more than one such value found */ public static Object findValueOfType(Collection<?> collection, Class<?>[] types) { if (isEmpty(collection) || Objects.isEmpty(types)) { return null; } for (Class<?> type : types) { Object value = findValueOfType(collection, type); if (value != null) { return value; } } return null; }