/** * Returns an immutable sorted set containing the elements of a sorted set, sorted by the same * {@code Comparator}. That behavior differs from {@link #copyOf(Iterable)}, which always uses the * natural ordering of the elements. * * <p>Despite the method name, this method attempts to avoid actually copying the data when it is * safe to do so. The exact circumstances under which a copy will or will not be performed are * undocumented and subject to change. * * <p>This method is safe to use even when {@code sortedSet} is a synchronized or concurrent * collection that is currently being modified by another thread. * * @throws NullPointerException if {@code sortedSet} or any of its elements is null */ public static <E> ImmutableSortedSet<E> copyOfSorted(SortedSet<E> sortedSet) { Comparator<? super E> comparator = SortedIterables.comparator(sortedSet); ImmutableList<E> list = ImmutableList.copyOf(sortedSet); if (list.isEmpty()) { return emptySet(comparator); } else { return new RegularImmutableSortedSet<E>(list, comparator); } }
/** * Combines multiple iterables into a single iterable. The returned iterable has an iterator that * traverses the elements of each iterable in {@code inputs}. The input iterators are not polled * until necessary. * * <p>The returned iterable's iterator supports {@code remove()} when the corresponding input * iterator supports it. * * @throws NullPointerException if any of the provided iterables is null */ public static <T> Iterable<T> concat(Iterable<? extends T>... inputs) { return concat(ImmutableList.copyOf(inputs)); }