This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-collections.git
commit d6e14a6b2298c4f8115d873b70e16284d2fbb375 Author: Gary Gregory <[email protected]> AuthorDate: Sat Oct 19 11:55:47 2024 -0400 Sort members --- .../apache/commons/collections4/IteratorUtils.java | 42 +++++++++++----------- .../apache/commons/collections4/bag/TreeBag.java | 20 +++++------ .../iterators/CartesianProductIteratorTest.java | 24 ++++++------- .../collections4/iterators/IteratorChainTest.java | 30 ++++++++-------- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/IteratorUtils.java b/src/main/java/org/apache/commons/collections4/IteratorUtils.java index ac21499be..f8678be60 100644 --- a/src/main/java/org/apache/commons/collections4/IteratorUtils.java +++ b/src/main/java/org/apache/commons/collections4/IteratorUtils.java @@ -427,27 +427,6 @@ public class IteratorUtils { return new IteratorChain<>(iterators); } - /** - * Gets an iterator that iterates through an {@link Iterator} of Iterators one after another. - * - * @param <E> the element type - * @param iterators the iterators to use, not null or empty or contain nulls - * @return a combination iterator over the iterators - * @throws NullPointerException if iterators collection is null or contains a null - * @throws ClassCastException if the iterators collection contains the wrong object type - * @since 4.5.0-M3 - */ - public static <E> Iterator<E> chainedIterator(final Iterator<? extends Iterator<? extends E>> iterators) { - return new LazyIteratorChain<E>() { - - @Override - protected Iterator<? extends E> nextIterator(final int count) { - return iterators.hasNext() ? iterators.next() : null; - } - - }; - } - /** * Gets an iterator that iterates through an array of {@link Iterator}s * one after another. @@ -478,6 +457,27 @@ public class IteratorUtils { return new IteratorChain<>(iterator1, iterator2); } + /** + * Gets an iterator that iterates through an {@link Iterator} of Iterators one after another. + * + * @param <E> the element type + * @param iterators the iterators to use, not null or empty or contain nulls + * @return a combination iterator over the iterators + * @throws NullPointerException if iterators collection is null or contains a null + * @throws ClassCastException if the iterators collection contains the wrong object type + * @since 4.5.0-M3 + */ + public static <E> Iterator<E> chainedIterator(final Iterator<? extends Iterator<? extends E>> iterators) { + return new LazyIteratorChain<E>() { + + @Override + protected Iterator<? extends E> nextIterator(final int count) { + return iterators.hasNext() ? iterators.next() : null; + } + + }; + } + /** * Gets an iterator that provides an ordered iteration over the elements * contained in a collection of {@link Iterator}s. diff --git a/src/main/java/org/apache/commons/collections4/bag/TreeBag.java b/src/main/java/org/apache/commons/collections4/bag/TreeBag.java index 14f7a6802..dcd855925 100644 --- a/src/main/java/org/apache/commons/collections4/bag/TreeBag.java +++ b/src/main/java/org/apache/commons/collections4/bag/TreeBag.java @@ -67,16 +67,6 @@ public class TreeBag<E> extends AbstractMapBag<E> implements SortedBag<E>, Seria addAll(coll); } - /** - * Constructs a bag containing all the members of the given Iterable. - * - * @param iterable an iterable to copy into this bag. - * @since 4.5.0-M3 - */ - public TreeBag(final Iterable<? extends E> iterable) { - super(new TreeMap<>(), iterable); - } - /** * Constructs an empty bag that maintains order on its unique representative * members according to the given {@link Comparator}. @@ -87,6 +77,16 @@ public class TreeBag<E> extends AbstractMapBag<E> implements SortedBag<E>, Seria super(new TreeMap<>(comparator)); } + /** + * Constructs a bag containing all the members of the given Iterable. + * + * @param iterable an iterable to copy into this bag. + * @since 4.5.0-M3 + */ + public TreeBag(final Iterable<? extends E> iterable) { + super(new TreeMap<>(), iterable); + } + /** * {@inheritDoc} * diff --git a/src/test/java/org/apache/commons/collections4/iterators/CartesianProductIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/CartesianProductIteratorTest.java index b32eeb726..fde5475ed 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/CartesianProductIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/CartesianProductIteratorTest.java @@ -69,12 +69,6 @@ public class CartesianProductIteratorTest extends AbstractIteratorTest<List<Char return false; } - @Test - public void testRemoveThrows() { - final CartesianProductIterator<Character> it = makeObject(); - assertThrows(UnsupportedOperationException.class, it::remove); - } - @Test public void testEmptyCollection() { final CartesianProductIterator<Character> it = new CartesianProductIterator<>(letters, Collections.emptyList()); @@ -106,12 +100,12 @@ public class CartesianProductIteratorTest extends AbstractIteratorTest<List<Char } /** - * test checking that no tuples are returned when at least one of the lists is empty + * test checking that no tuples are returned when all the lists are empty */ @Test - public void testExhaustivityWithEmptyList() { + public void testExhaustivityWithAllEmptyLists() { final List<Character[]> resultsList = new ArrayList<>(); - final CartesianProductIterator<Character> it = new CartesianProductIterator<>(letters, emptyList, symbols); + final CartesianProductIterator<Character> it = new CartesianProductIterator<>(emptyList, emptyList, emptyList); while (it.hasNext()) { final List<Character> tuple = it.next(); resultsList.add(tuple.toArray(new Character[0])); @@ -151,12 +145,12 @@ public class CartesianProductIteratorTest extends AbstractIteratorTest<List<Char } /** - * test checking that no tuples are returned when all the lists are empty + * test checking that no tuples are returned when at least one of the lists is empty */ @Test - public void testExhaustivityWithAllEmptyLists() { + public void testExhaustivityWithEmptyList() { final List<Character[]> resultsList = new ArrayList<>(); - final CartesianProductIterator<Character> it = new CartesianProductIterator<>(emptyList, emptyList, emptyList); + final CartesianProductIterator<Character> it = new CartesianProductIterator<>(letters, emptyList, symbols); while (it.hasNext()) { final List<Character> tuple = it.next(); resultsList.add(tuple.toArray(new Character[0])); @@ -206,4 +200,10 @@ public class CartesianProductIteratorTest extends AbstractIteratorTest<List<Char } } } + + @Test + public void testRemoveThrows() { + final CartesianProductIterator<Character> it = makeObject(); + assertThrows(UnsupportedOperationException.class, it::remove); + } } diff --git a/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java b/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java index 022caf71b..1536b1084 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java @@ -93,6 +93,21 @@ public class IteratorChainTest extends AbstractIteratorTest<String> { list3.add("Six"); } + @Test + public void testConstructList() { + final List<Iterator<String>> list = new ArrayList<>(); + list.add(list1.iterator()); + list.add(list2.iterator()); + list.add(list3.iterator()); + final List<String> expected = new ArrayList<>(list1); + expected.addAll(list2); + expected.addAll(list3); + final IteratorChain<String> iter = new IteratorChain<>(list); + final List<String> actual = new ArrayList<>(); + iter.forEachRemaining(actual::add); + assertEquals(actual, expected); + } + @Test public void testEmptyChain() { final IteratorChain<Object> chain = new IteratorChain<>(); @@ -137,21 +152,6 @@ public class IteratorChainTest extends AbstractIteratorTest<String> { } } - @Test - public void testConstructList() { - final List<Iterator<String>> list = new ArrayList<>(); - list.add(list1.iterator()); - list.add(list2.iterator()); - list.add(list3.iterator()); - final List<String> expected = new ArrayList<>(list1); - expected.addAll(list2); - expected.addAll(list3); - final IteratorChain<String> iter = new IteratorChain<>(list); - final List<String> actual = new ArrayList<>(); - iter.forEachRemaining(actual::add); - assertEquals(actual, expected); - } - @Test @Override public void testRemove() {
