paulk-asert commented on code in PR #703:
URL: 
https://github.com/apache/commons-collections/pull/703#discussion_r3532132669


##########
src/main/java/org/apache/commons/collections4/MultiSetUtils.java:
##########
@@ -67,6 +124,100 @@ public static <E> MultiSet<E> predicatedMultiSet(final 
MultiSet<E> multiset,
         return PredicatedMultiSet.predicatedMultiSet(multiset, predicate);
     }
 
+    /**
+     * Returns a predicated (validating) sorted multiset backed by the given 
sorted
+     * multiset.
+     * <p>
+     * Only objects that pass the test in the given predicate can be added to
+     * the multiset. Trying to add an invalid object results in an
+     * IllegalArgumentException. It is important not to use the original 
multiset
+     * after invoking this method, as it is a backdoor for adding invalid
+     * objects.
+     * </p>
+     *
+     * @param <E> The element type
+     * @param multiset the sorted multiset to predicate, must not be null
+     * @param predicate the predicate for the multiset, must not be null
+     * @return a predicated sorted multiset backed by the given sorted multiset
+     * @throws NullPointerException if the SortedMultiSet or Predicate is null
+     * @since 4.6.0
+     */
+    public static <E> SortedMultiSet<E> predicatedSortedMultiSet(final 
SortedMultiSet<E> multiset,
+            final Predicate<? super E> predicate) {
+        return PredicatedSortedMultiSet.predicatedSortedMultiSet(multiset, 
predicate);
+    }
+
+    /**
+     * For each occurrence of an element in {@code occurrencesToRemove}, 
removes
+     * one occurrence of that element from {@code multiSetToModify}, if 
present.
+     * That is, if {@code occurrencesToRemove} contains {@code n} occurrences 
of
+     * an element, {@code multiSetToModify} will have {@code n} fewer 
occurrences,
+     * assuming it had at least {@code n} to begin with.
+     * <p>
+     * This method provides the cardinality-respecting behavior of
+     * {@link Bag#removeAll(java.util.Collection)} under an explicitly named
+     * method. To remove the occurrences of a plain collection, wrap it first,
+     * for example {@code removeOccurrences(multiSet, new 
HashMultiSet<>(coll))}.
+     * </p>
+     *
+     * @param multiSetToModify the multiset to remove occurrences from, must 
not be null
+     * @param occurrencesToRemove the occurrences to remove, must not be null
+     * @return {@code true} if {@code multiSetToModify} was changed as a 
result of this operation
+     * @throws NullPointerException if either MultiSet is null
+     * @since 4.6.0
+     */
+    public static boolean removeOccurrences(final MultiSet<?> 
multiSetToModify, final MultiSet<?> occurrencesToRemove) {
+        Objects.requireNonNull(multiSetToModify, "multiSetToModify");
+        Objects.requireNonNull(occurrencesToRemove, "occurrencesToRemove");
+        if (multiSetToModify == occurrencesToRemove) {
+            final boolean changed = !multiSetToModify.isEmpty();
+            multiSetToModify.clear();
+            return changed;
+        }
+        boolean changed = false;
+        for (final MultiSet.Entry<?> entry : occurrencesToRemove.entrySet()) {
+            if (multiSetToModify.remove(entry.getElement(), entry.getCount()) 
> 0) {
+                changed = true;
+            }
+        }

Review Comment:
   fixed by iterating a snapshot



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to