@ SafeVarargs @ SuppressWarnings ( "unchecked" ) public static < T > Iterable < T > compositeIterable ( Iterable < T > ... iterables ) { Require . nonNull ( iterables , "iterables" ) ; final Iterator < T > it ; if ( iterables . length == 0 ) { it = Collections . emptyIterator ( ) ; } else if ( iterables . length == 1 ) { return iterables [ 0 ] ; } else { final Iterator < T > [ ] iterators = Arrays . stream ( iterables ) . map ( Iterable :: iterator ) . toArray ( size -> new Iterator [ size ] ) ; it = new CompoundIterator < T > ( iterators ) ; } return iterableOf ( it ) ; }
Creates an iterable which returns a composite iterator over all iterators of the given iterables .