[COLLECTIONS-472] Improved performance of AbstractMapBag#containsAll. Thanks to Adrian Nistor.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1491258 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2013-06-09 18:35:24 +00:00
parent 8f5e319af8
commit edd64cfd82
3 changed files with 10 additions and 4 deletions

View File

@ -182,6 +182,8 @@ Changed classes / methods
Fixed Bugs
----------
o [COLLECTIONS-472] Improved performance of "AbstractMapBag#containsAll(Collection)" by returning immediately
after a difference has been found. Thanks to Adrian Nistor.
o [COLLECTIONS-461] Added additional clarification to javadoc of interface "Put" wrt return type of
"put(Object, Object)" method. Thanks to Matt Benson, sebb.
o [COLLECTIONS-447] Tree traversal with a TreeListIterator will not be affected anymore by the removal of an element directly after

View File

@ -22,6 +22,10 @@
<body>
<release version="4.0" date="TBA" description="Next release">
<action issue="COLLECTIONS-472" dev="tn" type="fix" due-to="Adrian Nistor">
Improved performance of "AbstractMapBag#containsAll(Collection)" by returning immediately
after a difference has been found.
</action>
<action issue="COLLECTIONS-466" dev="tn" type="update">
Replaced "Collection" with "Iterable" for method arguments where applicable.
</action>

View File

@ -147,14 +147,14 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @return <code>true</code> if the Bag contains all the collection
*/
boolean containsAll(final Bag<?> other) {
boolean result = true;
final Iterator<?> it = other.uniqueSet().iterator();
while (it.hasNext()) {
final Object current = it.next();
final boolean contains = getCount(current) >= other.getCount(current);
result = result && contains;
if (getCount(current) < other.getCount(current)) {
return false;
}
return result;
}
return true;
}
//-----------------------------------------------------------------------