Sort members

This commit is contained in:
Gary Gregory 2024-10-19 11:55:47 -04:00
parent c8cd99e431
commit d6e14a6b22
4 changed files with 58 additions and 58 deletions

View File

@ -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.

View File

@ -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}
*

View File

@ -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);
}
}

View File

@ -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() {