From d6e14a6b2298c4f8115d873b70e16284d2fbb375 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 19 Oct 2024 11:55:47 -0400 Subject: [PATCH] Sort members --- .../commons/collections4/IteratorUtils.java | 42 +++++++++---------- .../commons/collections4/bag/TreeBag.java | 20 ++++----- .../CartesianProductIteratorTest.java | 24 +++++------ .../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 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 Iterator chainedIterator(final Iterator> iterators) { - return new LazyIteratorChain() { - - @Override - protected Iterator 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 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 Iterator chainedIterator(final Iterator> iterators) { + return new LazyIteratorChain() { + + @Override + protected Iterator 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 extends AbstractMapBag implements SortedBag, 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 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 extends AbstractMapBag implements SortedBag, 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 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 it = makeObject(); - assertThrows(UnsupportedOperationException.class, it::remove); - } - @Test public void testEmptyCollection() { final CartesianProductIterator it = new CartesianProductIterator<>(letters, Collections.emptyList()); @@ -106,12 +100,12 @@ public class CartesianProductIteratorTest extends AbstractIteratorTest resultsList = new ArrayList<>(); - final CartesianProductIterator it = new CartesianProductIterator<>(letters, emptyList, symbols); + final CartesianProductIterator it = new CartesianProductIterator<>(emptyList, emptyList, emptyList); while (it.hasNext()) { final List tuple = it.next(); resultsList.add(tuple.toArray(new Character[0])); @@ -151,12 +145,12 @@ public class CartesianProductIteratorTest extends AbstractIteratorTest resultsList = new ArrayList<>(); - final CartesianProductIterator it = new CartesianProductIterator<>(emptyList, emptyList, emptyList); + final CartesianProductIterator it = new CartesianProductIterator<>(letters, emptyList, symbols); while (it.hasNext()) { final List tuple = it.next(); resultsList.add(tuple.toArray(new Character[0])); @@ -206,4 +200,10 @@ public class CartesianProductIteratorTest extends AbstractIteratorTest 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 { list3.add("Six"); } + @Test + public void testConstructList() { + final List> list = new ArrayList<>(); + list.add(list1.iterator()); + list.add(list2.iterator()); + list.add(list3.iterator()); + final List expected = new ArrayList<>(list1); + expected.addAll(list2); + expected.addAll(list3); + final IteratorChain iter = new IteratorChain<>(list); + final List actual = new ArrayList<>(); + iter.forEachRemaining(actual::add); + assertEquals(actual, expected); + } + @Test public void testEmptyChain() { final IteratorChain chain = new IteratorChain<>(); @@ -137,21 +152,6 @@ public class IteratorChainTest extends AbstractIteratorTest { } } - @Test - public void testConstructList() { - final List> list = new ArrayList<>(); - list.add(list1.iterator()); - list.add(list2.iterator()); - list.add(list3.iterator()); - final List expected = new ArrayList<>(list1); - expected.addAll(list2); - expected.addAll(list3); - final IteratorChain iter = new IteratorChain<>(list); - final List actual = new ArrayList<>(); - iter.forEachRemaining(actual::add); - assertEquals(actual, expected); - } - @Test @Override public void testRemove() {