From ad28a3cb5c5edae55fb7b0f4642ccbf14f3065c1 Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Sun, 19 Oct 2014 12:44:34 +0000 Subject: [PATCH] [COLLECTIONS-534] Added clarifiying comment about performance to CollectionBag.retainAll. Thanks to Oswaldo Olivo. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1632904 13f79535-47bb-0310-9956-ffa450edef68 --- src/changes/changes.xml | 5 ++++- .../commons/collections4/bag/CollectionBag.java | 16 +++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index d03bd5bce..fd3832a6c 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,8 +22,11 @@ + + Added clarifying javadoc wrt runtime complexity of "CollectionBag#retainAll". + - Clarify JavaDoc of MultiKey getKey() and size() + Clarify JavaDoc of MultiKey getKey() and size(). Added methods "removeAll(...)" and "retainAll(...)" to "CollectionUtils" that perform diff --git a/src/main/java/org/apache/commons/collections4/bag/CollectionBag.java b/src/main/java/org/apache/commons/collections4/bag/CollectionBag.java index bf53c61eb..73d02e89e 100644 --- a/src/main/java/org/apache/commons/collections4/bag/CollectionBag.java +++ b/src/main/java/org/apache/commons/collections4/bag/CollectionBag.java @@ -186,11 +186,17 @@ public final class CollectionBag extends AbstractBagDecorator { /** * (Change) - * Remove any members of the bag that are not in the given - * collection, not respecting cardinality. That is, any object - * in the given collection coll will be retained in the - * bag with the same number of copies prior to this operation. All - * other objects will be completely removed from this bag. + * Remove any members of the bag that are not in the given collection, + * not respecting cardinality. That is, any object in the given + * collection coll will be retained in the bag with the same + * number of copies prior to this operation. All other objects will be + * completely removed from this bag. + *

+ * This implementation iterates over the elements of this bag, checking + * each element in turn to see if it's contained in coll. + * If it's not contained, it's removed from this bag. As a consequence, + * it is advised to use a collection type for coll that provides + * a fast (e.g. O(1)) implementation of {@link Collection#contains(Object)}. * * @param coll the collection to retain * @return true if this call changed the collection