Remove custom EnumerationIterator
This commit removes our custom EnumerationIterator, in favor of Enumeration::asIterator (since JDK 9).
This commit is contained in:
parent
dd79be3664
commit
e4b493456b
|
|
@ -233,15 +233,14 @@ public abstract class CollectionUtils {
|
||||||
* @param candidates the candidates to search for
|
* @param candidates the candidates to search for
|
||||||
* @return the first present object, or {@code null} if not found
|
* @return the first present object, or {@code null} if not found
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static <E> E findFirstMatch(Collection<?> source, Collection<E> candidates) {
|
public static <E> E findFirstMatch(Collection<?> source, Collection<E> candidates) {
|
||||||
if (isEmpty(source) || isEmpty(candidates)) {
|
if (isEmpty(source) || isEmpty(candidates)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (Object candidate : candidates) {
|
for (E candidate : candidates) {
|
||||||
if (source.contains(candidate)) {
|
if (source.contains(candidate)) {
|
||||||
return (E) candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -447,7 +446,7 @@ public abstract class CollectionUtils {
|
||||||
* @return the adapted {@code Iterator}
|
* @return the adapted {@code Iterator}
|
||||||
*/
|
*/
|
||||||
public static <E> Iterator<E> toIterator(@Nullable Enumeration<E> enumeration) {
|
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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue