diff --git a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java index d1e9354abda..530e5222ba0 100644 --- a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java @@ -233,15 +233,14 @@ public abstract class CollectionUtils { * @param candidates the candidates to search for * @return the first present object, or {@code null} if not found */ - @SuppressWarnings("unchecked") @Nullable public static E findFirstMatch(Collection source, Collection candidates) { if (isEmpty(source) || isEmpty(candidates)) { return null; } - for (Object candidate : candidates) { + for (E candidate : candidates) { if (source.contains(candidate)) { - return (E) candidate; + return candidate; } } return null; @@ -447,7 +446,7 @@ public abstract class CollectionUtils { * @return the adapted {@code Iterator} */ public static Iterator toIterator(@Nullable Enumeration enumeration) { - return (enumeration != null ? new EnumerationIterator<>(enumeration) : Collections.emptyIterator()); + return (enumeration != null ? enumeration.asIterator() : Collections.emptyIterator()); } /** @@ -481,32 +480,4 @@ public abstract class CollectionUtils { } - /** - * Iterator wrapping an Enumeration. - */ - private static class EnumerationIterator implements Iterator { - - private final Enumeration enumeration; - - public EnumerationIterator(Enumeration enumeration) { - this.enumeration = enumeration; - } - - @Override - public boolean hasNext() { - return this.enumeration.hasMoreElements(); - } - - @Override - public E next() { - return this.enumeration.nextElement(); - } - - @Override - public void remove() throws UnsupportedOperationException { - throw new UnsupportedOperationException("Not supported"); - } - } - - }