GT-3354: Code review fixes

This commit is contained in:
Ryan Kurtz 2019-12-09 09:06:33 -05:00
parent 2a64cf2a77
commit e53e4c99fc
5 changed files with 34 additions and 10 deletions

View file

@ -398,6 +398,19 @@ public class CollectionUtils {
return () -> iterator;
}
/**
* Combines all collections passed-in into a pass-through not creating a new collection)
* Iterable.
*
* @param iterables the iterables to combine
* @return the iterable
*/
@SafeVarargs
public static <T> Iterable<T> asIterable(Iterable<T>... iterables) {
Stream<T> s = asStream(iterables);
return asIterable(s.iterator());
}
/**
* Turns the given iterator into a stream
*

View file

@ -225,6 +225,21 @@ public class CollectionUtilsTest {
assertEquals("One", iterator.next());
}
@Test
public void testAsIterable_Collections() {
List<String> original = Arrays.asList("One", "Two", "Three", "Four");
Collection<String> a = Arrays.asList(original.get(0), original.get(1));
Collection<String> b = Arrays.asList(original.get(2));
Collection<String> c = Collections.emptyList();
Collection<String> d = Arrays.asList(original.get(3));
Iterable<String> iterable = CollectionUtils.asIterable(a, b, c, d);
List<String> result = new ArrayList<>();
iterable.forEach(s -> result.add(s));
assertEquals(original, result);
}
@Test
public void testAsList_UnknownToType() {
List<String> list = new ArrayList<>();