COLLECTIONS-603: Small improvements for generics, conditional statements, and warnings suppressions
Thanks to Artem Konovalov This closes #17 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1796010 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a26fcf58e4
commit
9f0d58985f
|
@ -21,6 +21,9 @@
|
||||||
</properties>
|
</properties>
|
||||||
<body>
|
<body>
|
||||||
<release version="4.2" date="YYYY-MM-DD" description="New features">
|
<release version="4.2" date="YYYY-MM-DD" description="New features">
|
||||||
|
<action issue="COLLECTIONS-603" dev="kinow" type="fix" due-to="Artem Konovalov">
|
||||||
|
Small improvements for generics, conditional statements, and warnings suppressions.
|
||||||
|
</action>
|
||||||
<action issue="COLLECTIONS-594" dev="ggregory" type="fix" due-to="Javen O'Neal">
|
<action issue="COLLECTIONS-594" dev="ggregory" type="fix" due-to="Javen O'Neal">
|
||||||
Web site spelling error: MultiValuedMapeList.
|
Web site spelling error: MultiValuedMapeList.
|
||||||
</action>
|
</action>
|
||||||
|
|
|
@ -19,12 +19,12 @@ package org.apache.commons.collections4;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -180,8 +180,7 @@ public class CollectionUtils {
|
||||||
* undesirable. This implementation only implements Collection.
|
* undesirable. This implementation only implements Collection.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes") // we deliberately use the raw type here
|
@SuppressWarnings("rawtypes") // we deliberately use the raw type here
|
||||||
public static final Collection EMPTY_COLLECTION =
|
public static final Collection EMPTY_COLLECTION = Collections.emptyList();
|
||||||
UnmodifiableCollection.unmodifiableCollection(new ArrayList<Object>());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>CollectionUtils</code> should not normally be instantiated.
|
* <code>CollectionUtils</code> should not normally be instantiated.
|
||||||
|
@ -209,9 +208,8 @@ public class CollectionUtils {
|
||||||
* @param collection the collection, possibly <code>null</code>
|
* @param collection the collection, possibly <code>null</code>
|
||||||
* @return an empty collection if the argument is <code>null</code>
|
* @return an empty collection if the argument is <code>null</code>
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked") // OK, empty collection is compatible with any type
|
|
||||||
public static <T> Collection<T> emptyIfNull(final Collection<T> collection) {
|
public static <T> Collection<T> emptyIfNull(final Collection<T> collection) {
|
||||||
return collection == null ? EMPTY_COLLECTION : collection;
|
return collection == null ? CollectionUtils.<T>emptyCollection() : collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -389,9 +387,7 @@ public class CollectionUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundCurrentElement) {
|
if (!foundCurrentElement) {
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -830,7 +826,7 @@ public class CollectionUtils {
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static <C> boolean exists(final Iterable<C> input, final Predicate<? super C> predicate) {
|
public static <C> boolean exists(final Iterable<C> input, final Predicate<? super C> predicate) {
|
||||||
return predicate == null ? false : IterableUtils.matchesAny(input, predicate);
|
return predicate != null && IterableUtils.matchesAny(input, predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -850,7 +846,7 @@ public class CollectionUtils {
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static <C> boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate) {
|
public static <C> boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate) {
|
||||||
return predicate == null ? false : IterableUtils.matchesAll(input, predicate);
|
return predicate != null && IterableUtils.matchesAll(input, predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1266,9 +1262,6 @@ public class CollectionUtils {
|
||||||
} else if (object instanceof Iterable<?>) {
|
} else if (object instanceof Iterable<?>) {
|
||||||
final Iterable<?> iterable = (Iterable<?>) object;
|
final Iterable<?> iterable = (Iterable<?>) object;
|
||||||
return IterableUtils.get(iterable, i);
|
return IterableUtils.get(iterable, i);
|
||||||
} else if (object instanceof Collection<?>) {
|
|
||||||
final Iterator<?> iterator = ((Collection<?>) object).iterator();
|
|
||||||
return IteratorUtils.get(iterator, i);
|
|
||||||
} else if (object instanceof Enumeration<?>) {
|
} else if (object instanceof Enumeration<?>) {
|
||||||
final Enumeration<?> it = (Enumeration<?>) object;
|
final Enumeration<?> it = (Enumeration<?>) object;
|
||||||
return EnumerationUtils.get(it, i);
|
return EnumerationUtils.get(it, i);
|
||||||
|
@ -1631,7 +1624,7 @@ public class CollectionUtils {
|
||||||
*/
|
*/
|
||||||
public static <E> Collection<List<E>> permutations(final Collection<E> collection) {
|
public static <E> Collection<List<E>> permutations(final Collection<E> collection) {
|
||||||
final PermutationIterator<E> it = new PermutationIterator<E>(collection);
|
final PermutationIterator<E> it = new PermutationIterator<E>(collection);
|
||||||
final Collection<List<E>> result = new LinkedList<List<E>>();
|
final Collection<List<E>> result = new ArrayList<List<E>>();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
result.add(it.next());
|
result.add(it.next());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue