|
|
|
|
@ -233,15 +233,14 @@ public abstract class CollectionUtils {
@@ -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> E findFirstMatch(Collection<?> source, Collection<E> 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 {
@@ -447,7 +446,7 @@ public abstract class CollectionUtils {
|
|
|
|
|
* @return the adapted {@code Iterator} |
|
|
|
|
*/ |
|
|
|
|
public static <E> Iterator<E> toIterator(@Nullable Enumeration<E> enumeration) { |
|
|
|
|
return (enumeration != null ? new EnumerationIterator<>(enumeration) : Collections.emptyIterator()); |
|
|
|
|
return (enumeration != null ? enumeration.asIterator() : Collections.emptyIterator()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -481,32 +480,4 @@ public abstract class CollectionUtils {
@@ -481,32 +480,4 @@ public abstract class CollectionUtils {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Iterator wrapping an Enumeration. |
|
|
|
|
*/ |
|
|
|
|
private static class EnumerationIterator<E> implements Iterator<E> { |
|
|
|
|
|
|
|
|
|
private final Enumeration<E> enumeration; |
|
|
|
|
|
|
|
|
|
public EnumerationIterator(Enumeration<E> 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"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|