[COLLECTIONS-531] Use proper type bounds for CollectionUtils.isEqualCollection(C, C, Equator). Thanks to Dipanjan Laha.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1598357 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0a114bbdb0
commit
bb0a4b6b03
|
@ -22,6 +22,11 @@
|
|||
<body>
|
||||
|
||||
<release version="4.1" date="TBD" description="">
|
||||
<action issue="COLLECTIONS-531" dev="tn" type="fix" due-to="Dipanjan Laha">
|
||||
Use correct type bounds in
|
||||
"CollectionUtils#isEqualCollection(Collection, Collection, Equator)" to
|
||||
prevent a "ClassCastException" at runtime for invalid inputs.
|
||||
</action>
|
||||
<action issue="COLLECTIONS-523" dev="tn" type="fix" due-to="Thiago Andrade">
|
||||
Removed unneeded private method in "PassiveExpiringMap".
|
||||
</action>
|
||||
|
|
|
@ -534,7 +534,13 @@ public class CollectionUtils {
|
|||
* That is, iff the cardinality of <i>e</i> in <i>a</i> is
|
||||
* equal to the cardinality of <i>e</i> in <i>b</i>,
|
||||
* for each element <i>e</i> in <i>a</i> or <i>b</i>.
|
||||
* <p>
|
||||
* <b>Note:</b> from version 4.1 onwards this method requires the input
|
||||
* collections and equator to be of compatible type (using bounded wildcards).
|
||||
* Providing incompatible arguments (e.g. by casting to their rawtypes)
|
||||
* will result in a {@code ClassCastException} thrown at runtime.
|
||||
*
|
||||
* @param <E> the element type
|
||||
* @param a the first collection, must not be null
|
||||
* @param b the second collection, must not be null
|
||||
* @param equator the Equator used for testing equality
|
||||
|
@ -542,8 +548,9 @@ public class CollectionUtils {
|
|||
* @throws IllegalArgumentException if the equator is null
|
||||
* @since 4.0
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" }) // we don't know the types due to wildcards in the signature
|
||||
public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b, final Equator<?> equator) {
|
||||
public static <E> boolean isEqualCollection(final Collection<? extends E> a,
|
||||
final Collection<? extends E> b,
|
||||
final Equator<? super E> equator) {
|
||||
if (equator == null) {
|
||||
throw new IllegalArgumentException("equator may not be null");
|
||||
}
|
||||
|
@ -552,7 +559,8 @@ public class CollectionUtils {
|
|||
return false;
|
||||
}
|
||||
|
||||
final Transformer transformer = new Transformer() {
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
final Transformer<E, ?> transformer = new Transformer() {
|
||||
public EquatorWrapper<?> transform(final Object input) {
|
||||
return new EquatorWrapper(equator, input);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue