You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "paulk-asert (via GitHub)" <gi...@apache.org> on 2026/07/04 23:52:27 UTC
[PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
paulk-asert opened a new pull request, #703:
URL: https://github.com/apache/commons-collections/pull/703
see: https://issues.apache.org/jira/browse/COLLECTIONS-893
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory merged PR #703:
URL: https://github.com/apache/commons-collections/pull/703
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #703:
URL: https://github.com/apache/commons-collections/pull/703#issuecomment-4885680973
This is an in-progress PR, right? I see commented out code and test fixtures that are unused (since the code is commented out).
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert commented on PR #703:
URL: https://github.com/apache/commons-collections/pull/703#issuecomment-4930396110
In theory, the Bag classes could be deprecated whenever the project is ready. I haven't done that but let me know if you want a PR for that.
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #703:
URL: https://github.com/apache/commons-collections/pull/703#discussion_r3531824784
##########
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:
removeOccurrences iterates directly over occurrencesToRemove.entrySet() while mutating multiSetToModify. If occurrencesToRemove is backed by the same multiset (e.g., an unmodifiable view of multiSetToModify), this will typically throw ConcurrentModificationException due to the fail-fast iterator. Iterating over a defensive copy avoids this and still preserves the intended semantics.
##########
src/test/java/org/apache/commons/collections4/multiset/UnmodifiableSortedMultiSetTest.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.collections4.multiset;
+
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Arrays;
+
+import org.apache.commons.collections4.SortedMultiSet;
+import org.apache.commons.collections4.Unmodifiable;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Extension of {@link AbstractSortedMultiSetTest} for exercising the
+ * {@link UnmodifiableSortedMultiSet} implementation.
+ */
+public class UnmodifiableSortedMultiSetTest<E> extends AbstractSortedMultiSetTest<E> {
+
+ @Override
+ public String getCompatibilityVersion() {
+ return "4.6";
+ }
+
+ @Override
+ public boolean isAddSupported() {
+ return false;
+ }
+
+ @Override
+ public boolean isRemoveSupported() {
+ return false;
+ }
+
+ @Override
+ public SortedMultiSet<E> makeFullCollection() {
+ final SortedMultiSet<E> multiset = new TreeMultiSet<>();
+ multiset.addAll(Arrays.asList(getFullElements()));
+ return UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(multiset);
+ }
+
+ @Override
+ public SortedMultiSet<E> makeObject() {
+ return UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(new TreeMultiSet<>());
+ }
+
+ @Test
+ void testAdd() {
+ final SortedMultiSet<E> multiset = makeFullCollection();
+ final SortedMultiSet<E> unmodifiableMultiSet = UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(multiset);
+ assertThrows(UnsupportedOperationException.class, () -> unmodifiableMultiSet.add((E) "One", 1));
+ }
+
+ @Test
+ void testDecorateFactory() {
+ final SortedMultiSet<E> multiset = makeFullCollection();
+ assertSame(multiset, UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(multiset));
+
+ assertThrows(NullPointerException.class, () -> UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(null));
+ }
+
+ @Test
+ void testEntrySet() {
+ final SortedMultiSet<E> multiset = makeFullCollection();
+ final SortedMultiSet<E> unmodifiableMultiSet = UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(multiset);
+ assertSame(unmodifiableMultiSet.entrySet().size(), multiset.entrySet().size());
+ }
Review Comment:
assertSame compares object identity, not numeric equality. Here it boxes the int sizes to Integer and relies on caching; this is fragile and can fail if sizes exceed the cache range or if boxing behavior changes. Use assertEquals to validate the sizes are equal.
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #703:
URL: https://github.com/apache/commons-collections/pull/703#issuecomment-4930604253
@paulk-asert
That sounds like a good idea, a PR would be great, TY!
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #703:
URL: https://github.com/apache/commons-collections/pull/703#discussion_r3535938711
##########
src/main/java/org/apache/commons/collections4/Bag.java:
##########
@@ -40,8 +40,34 @@
* In an ideal world, the interface would be changed to fix the problems, however
* it has been decided to maintain backwards compatibility instead.
* </p>
+ * <p>
+ * The {@link MultiSet} interface, added in version 4.1, provides the same
+ * functionality while complying with the {@link Collection} contract, and
+ * should be preferred for new code. Existing code can migrate as follows,
+ * with the cardinality-respecting behavior preserved through explicitly
+ * named methods:
+ * </p>
+ * <ul>
+ * <li>{@code bag.add(e)} becomes {@code multiSet.add(e)}
+ * (which always returns {@code true}, per the {@code Collection} contract)</li>
Review Comment:
Hello @paulk-asert
The Collection contract says:
```java
* @return {@code true} if this collection changed as a result of the
* call
```
Which is not what this Javadoc says. Shouldn't the reference here be to `MultiSet.add(E)` instead of `Collection.add(E)`? Or clarify it somehow... yes, it always returns true but that's not what the Collection.add() docs say... exactly.
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #703:
URL: https://github.com/apache/commons-collections/pull/703#discussion_r3535938711
##########
src/main/java/org/apache/commons/collections4/Bag.java:
##########
@@ -40,8 +40,34 @@
* In an ideal world, the interface would be changed to fix the problems, however
* it has been decided to maintain backwards compatibility instead.
* </p>
+ * <p>
+ * The {@link MultiSet} interface, added in version 4.1, provides the same
+ * functionality while complying with the {@link Collection} contract, and
+ * should be preferred for new code. Existing code can migrate as follows,
+ * with the cardinality-respecting behavior preserved through explicitly
+ * named methods:
+ * </p>
+ * <ul>
+ * <li>{@code bag.add(e)} becomes {@code multiSet.add(e)}
+ * (which always returns {@code true}, per the {@code Collection} contract)</li>
Review Comment:
Hello @paulk-asert
The Collection contract says:
```java
* @return {@code true} if this collection changed as a result of the
* call
```
Which is not what this Javadoc says. Shouldn't the reference here be to `MultiSet.add(E)` instead of `Collection.add(E)`?
```java
* <li>{@code bag.add(e)} becomes {@code multiSet.add(e)}
* (which always returns {@code true}, per the {@code MultiSet} contract)</li>
```
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #703:
URL: https://github.com/apache/commons-collections/pull/703#issuecomment-4930103067
Thank you @paulk-asert ; merged ๐
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert commented on code in PR #703:
URL: https://github.com/apache/commons-collections/pull/703#discussion_r3536438410
##########
src/main/java/org/apache/commons/collections4/Bag.java:
##########
@@ -40,8 +40,34 @@
* In an ideal world, the interface would be changed to fix the problems, however
* it has been decided to maintain backwards compatibility instead.
* </p>
+ * <p>
+ * The {@link MultiSet} interface, added in version 4.1, provides the same
+ * functionality while complying with the {@link Collection} contract, and
+ * should be preferred for new code. Existing code can migrate as follows,
+ * with the cardinality-respecting behavior preserved through explicitly
+ * named methods:
+ * </p>
+ * <ul>
+ * <li>{@code bag.add(e)} becomes {@code multiSet.add(e)}
+ * (which always returns {@code true}, per the {@code Collection} contract)</li>
Review Comment:
Yeah, MultiSet is clearer. Changed.
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #703:
URL: https://github.com/apache/commons-collections/pull/703#discussion_r3535938711
##########
src/main/java/org/apache/commons/collections4/Bag.java:
##########
@@ -40,8 +40,34 @@
* In an ideal world, the interface would be changed to fix the problems, however
* it has been decided to maintain backwards compatibility instead.
* </p>
+ * <p>
+ * The {@link MultiSet} interface, added in version 4.1, provides the same
+ * functionality while complying with the {@link Collection} contract, and
+ * should be preferred for new code. Existing code can migrate as follows,
+ * with the cardinality-respecting behavior preserved through explicitly
+ * named methods:
+ * </p>
+ * <ul>
+ * <li>{@code bag.add(e)} becomes {@code multiSet.add(e)}
+ * (which always returns {@code true}, per the {@code Collection} contract)</li>
Review Comment:
Hello @paulk-asert
The Collection contract says:
```java
* @return {@code true} if this collection changed as a result of the
* call
```
Which is not what this Javadoc says. Shouldn't the reference here be to `MultiSet.add(E)` instead of `Collection.add(E)`? Or clarify it somehow...
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
Posted by Sungchan Park <sc...@gmail.com>.
Unsubscribe
๋์ iPhone์์ ๋ณด๋
> 2026. 7. 7. ์ค์ 6:26, paulk-asert <gi...@apache.org> ์์ฑ:
>
> ๏ปฟ
> paulk-asert commented on code in PR #703:
> URL: https://github.com/apache/commons-collections/pull/703#discussion_r3532139242
>
>
> ##########
> src/test/java/org/apache/commons/collections4/multiset/UnmodifiableSortedMultiSetTest.java:
> ##########
> @@ -0,0 +1,111 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements. See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License. You may obtain a copy of the License at
> + *
> + * https://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.commons.collections4.multiset;
> +
> +import static org.junit.jupiter.api.Assertions.assertSame;
> +import static org.junit.jupiter.api.Assertions.assertThrows;
> +import static org.junit.jupiter.api.Assertions.assertTrue;
> +
> +import java.util.Arrays;
> +
> +import org.apache.commons.collections4.SortedMultiSet;
> +import org.apache.commons.collections4.Unmodifiable;
> +import org.junit.jupiter.api.Test;
> +
> +/**
> + * Extension of {@link AbstractSortedMultiSetTest} for exercising the
> + * {@link UnmodifiableSortedMultiSet} implementation.
> + */
> +public class UnmodifiableSortedMultiSetTest<E> extends AbstractSortedMultiSetTest<E> {
> +
> + @Override
> + public String getCompatibilityVersion() {
> + return "4.6";
> + }
> +
> + @Override
> + public boolean isAddSupported() {
> + return false;
> + }
> +
> + @Override
> + public boolean isRemoveSupported() {
> + return false;
> + }
> +
> + @Override
> + public SortedMultiSet<E> makeFullCollection() {
> + final SortedMultiSet<E> multiset = new TreeMultiSet<>();
> + multiset.addAll(Arrays.asList(getFullElements()));
> + return UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(multiset);
> + }
> +
> + @Override
> + public SortedMultiSet<E> makeObject() {
> + return UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(new TreeMultiSet<>());
> + }
> +
> + @Test
> + void testAdd() {
> + final SortedMultiSet<E> multiset = makeFullCollection();
> + final SortedMultiSet<E> unmodifiableMultiSet = UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(multiset);
> + assertThrows(UnsupportedOperationException.class, () -> unmodifiableMultiSet.add((E) "One", 1));
> + }
> +
> + @Test
> + void testDecorateFactory() {
> + final SortedMultiSet<E> multiset = makeFullCollection();
> + assertSame(multiset, UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(multiset));
> +
> + assertThrows(NullPointerException.class, () -> UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(null));
> + }
> +
> + @Test
> + void testEntrySet() {
> + final SortedMultiSet<E> multiset = makeFullCollection();
> + final SortedMultiSet<E> unmodifiableMultiSet = UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(multiset);
> + assertSame(unmodifiableMultiSet.entrySet().size(), multiset.entrySet().size());
> + }
>
> Review Comment:
> fixed and did the same for the existing UnmodifiableMultiSetTest too
>
>
>
> --
> 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: issues-unsubscribe@commons.apache.org
>
> For queries about this service, please contact Infrastructure at:
> users@infra.apache.org
>
Re: [PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert commented on code in PR #703:
URL: https://github.com/apache/commons-collections/pull/703#discussion_r3532139242
##########
src/test/java/org/apache/commons/collections4/multiset/UnmodifiableSortedMultiSetTest.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.collections4.multiset;
+
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Arrays;
+
+import org.apache.commons.collections4.SortedMultiSet;
+import org.apache.commons.collections4.Unmodifiable;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Extension of {@link AbstractSortedMultiSetTest} for exercising the
+ * {@link UnmodifiableSortedMultiSet} implementation.
+ */
+public class UnmodifiableSortedMultiSetTest<E> extends AbstractSortedMultiSetTest<E> {
+
+ @Override
+ public String getCompatibilityVersion() {
+ return "4.6";
+ }
+
+ @Override
+ public boolean isAddSupported() {
+ return false;
+ }
+
+ @Override
+ public boolean isRemoveSupported() {
+ return false;
+ }
+
+ @Override
+ public SortedMultiSet<E> makeFullCollection() {
+ final SortedMultiSet<E> multiset = new TreeMultiSet<>();
+ multiset.addAll(Arrays.asList(getFullElements()));
+ return UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(multiset);
+ }
+
+ @Override
+ public SortedMultiSet<E> makeObject() {
+ return UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(new TreeMultiSet<>());
+ }
+
+ @Test
+ void testAdd() {
+ final SortedMultiSet<E> multiset = makeFullCollection();
+ final SortedMultiSet<E> unmodifiableMultiSet = UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(multiset);
+ assertThrows(UnsupportedOperationException.class, () -> unmodifiableMultiSet.add((E) "One", 1));
+ }
+
+ @Test
+ void testDecorateFactory() {
+ final SortedMultiSet<E> multiset = makeFullCollection();
+ assertSame(multiset, UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(multiset));
+
+ assertThrows(NullPointerException.class, () -> UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(null));
+ }
+
+ @Test
+ void testEntrySet() {
+ final SortedMultiSet<E> multiset = makeFullCollection();
+ final SortedMultiSet<E> unmodifiableMultiSet = UnmodifiableSortedMultiSet.unmodifiableSortedMultiSet(multiset);
+ assertSame(unmodifiableMultiSet.entrySet().size(), multiset.entrySet().size());
+ }
Review Comment:
fixed and did the same for the existing UnmodifiableMultiSetTest too
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] COLLECTIONS-893: Bring (Collection compliant) MultiSet family to (non-compliant) Bag parity [commons-collections]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert commented on PR #703:
URL: https://github.com/apache/commons-collections/pull/703#issuecomment-4885940125
The commented out parts are the parts used to create the .obj files. I am not familiar enough with that convention to know whether I did the right thing there.
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org