public SqlParserOptions allowIdentifierSymbol(Iterable<IdentifierSymbol> identifierSymbols) { Iterables.addAll(allowedIdentifierSymbols, identifierSymbols); return this; }
/** * Returns a new, <i>mutable</i> {@code EnumSet} instance containing the given elements in their * natural order. This method behaves identically to {@link EnumSet#copyOf(Collection)}, but also * accepts non-{@code Collection} iterables and empty iterables. */ public static <E extends Enum<E>> EnumSet<E> newEnumSet( Iterable<E> iterable, Class<E> elementType) { EnumSet<E> set = EnumSet.noneOf(elementType); Iterables.addAll(set, iterable); return set; }
/** * Creates a new {@code HashMultiset} containing the specified elements. * * <p>This implementation is highly efficient when {@code elements} is itself a {@link Multiset}. * * @param elements the elements that the multiset should contain */ public static <E> HashMultiset<E> create(Iterable<? extends E> elements) { HashMultiset<E> multiset = create(Multisets.inferDistinctElements(elements)); Iterables.addAll(multiset, elements); return multiset; }
/** * Returns a new {@code EnumMultiset} instance containing the given elements. Unlike {@link * EnumMultiset#create(Iterable)}, this method does not produce an exception on an empty iterable. * * @since 14.0 */ public static <E extends Enum<E>> EnumMultiset<E> create(Iterable<E> elements, Class<E> type) { EnumMultiset<E> result = create(type); Iterables.addAll(result, elements); return result; }
/** * Creates a new {@code ConcurrentHashMultiset} containing the specified elements, using the * default initial capacity, load factor, and concurrency settings. * * <p>This implementation is highly efficient when {@code elements} is itself a {@link Multiset}. * * @param elements the elements that the multiset should contain */ public static <E> ConcurrentHashMultiset<E> create(Iterable<? extends E> elements) { ConcurrentHashMultiset<E> multiset = ConcurrentHashMultiset.create(); Iterables.addAll(multiset, elements); return multiset; }
/** * Creates an empty multiset containing the given initial elements, sorted according to the * elements' natural order. * * <p>This implementation is highly efficient when {@code elements} is itself a {@link Multiset}. * * <p>The type specification is {@code <E extends Comparable>}, instead of the more specific * {@code <E extends Comparable<? super E>>}, to support classes defined without generics. */ public static <E extends Comparable> TreeMultiset<E> create(Iterable<? extends E> elements) { TreeMultiset<E> multiset = create(); Iterables.addAll(multiset, elements); return multiset; }
/** * Creates an {@code ArrayDeque} containing the elements of the specified iterable, in the order * they are returned by the iterable's iterator. * * @since 12.0 */ public static <E> ArrayDeque<E> newArrayDeque(Iterable<? extends E> elements) { if (elements instanceof Collection) { return new ArrayDeque<E>(Collections2.cast(elements)); } ArrayDeque<E> deque = new ArrayDeque<E>(); Iterables.addAll(deque, elements); return deque; }
/** * Creates a new {@code EnumMultiset} containing the specified elements. * * <p>This implementation is highly efficient when {@code elements} is itself a {@link Multiset}. * * @param elements the elements that the multiset should contain * @throws IllegalArgumentException if {@code elements} is empty */ public static <E extends Enum<E>> EnumMultiset<E> create(Iterable<E> elements) { Iterator<E> iterator = elements.iterator(); checkArgument(iterator.hasNext(), "EnumMultiset constructor passed empty Iterable"); EnumMultiset<E> multiset = new EnumMultiset<>(iterator.next().getDeclaringClass()); Iterables.addAll(multiset, elements); return multiset; }
/** * Creates a {@code PriorityQueue} containing the given elements. * * <p><b>Note:</b> If the specified iterable is a {@code SortedSet} or a {@code PriorityQueue}, * this priority queue will be ordered according to the same ordering. * * @since 11.0 (requires that {@code E} be {@code Comparable} since 15.0). */ public static <E extends Comparable> PriorityQueue<E> newPriorityQueue( Iterable<? extends E> elements) { if (elements instanceof Collection) { return new PriorityQueue<E>(Collections2.cast(elements)); } PriorityQueue<E> queue = new PriorityQueue<E>(); Iterables.addAll(queue, elements); return queue; }
/** * Creates a thread-safe set backed by a hash map and containing the given elements. The set is * backed by a {@link ConcurrentHashMap} instance, and thus carries the same concurrency * guarantees. * * <p>Unlike {@code HashSet}, this class does NOT allow {@code null} to be used as an element. The * set is serializable. * * @param elements the elements that the set should contain * @return a new thread-safe set containing those elements (minus duplicates) * @throws NullPointerException if {@code elements} or any of its contents is null * @since 15.0 */ public static <E> Set<E> newConcurrentHashSet(Iterable<? extends E> elements) { Set<E> set = newConcurrentHashSet(); Iterables.addAll(set, elements); return set; }
private ImmutableList<IndexItem<?, Object>> loadSezpozIndices(ClassLoader classLoader) { List<IndexItem<?,Object>> indices = Lists.newArrayList(); for (GuiceExtensionAnnotation<?> gea : extensionAnnotations.values()) { Iterables.addAll(indices, Index.load(gea.annotationType, Object.class, classLoader)); } return ImmutableList.copyOf(indices); }
public synchronized void addPages(Iterable<Page> pages, boolean close) { Iterables.addAll(buffer, pages); if (close) { closed = true; } }
/** * Creates a <i>mutable</i> {@code LinkedList} instance containing the given elements; a very thin * shortcut for creating an empty list then calling {@link Iterables#addAll}. * * <p><b>Note:</b> if mutability is not required and the elements are non-null, use {@link * ImmutableList#copyOf(Iterable)} instead. (Or, change {@code elements} to be a {@link * FluentIterable} and call {@code elements.toList()}.) * * <p><b>Performance note:</b> {@link ArrayList} and {@link java.util.ArrayDeque} consistently * outperform {@code LinkedList} except in certain rare and specific situations. Unless you have * spent a lot of time benchmarking your specific needs, use one of those instead. * * <p><b>Note for Java 7 and later:</b> if {@code elements} is a {@link Collection}, you don't * need this method. Use the {@code LinkedList} {@linkplain LinkedList#LinkedList(Collection) * constructor} directly, taking advantage of the new <a href="http://goo.gl/iz2Wi">"diamond" * syntax</a>. */ @GwtCompatible(serializable = true) public static <E> LinkedList<E> newLinkedList(Iterable<? extends E> elements) { LinkedList<E> list = newLinkedList(); Iterables.addAll(list, elements); return list; }
/** * Creates a {@code ConcurrentLinkedQueue} containing the elements of the specified iterable, in * the order they are returned by the iterable's iterator. */ @GwtIncompatible // ConcurrentLinkedQueue public static <E> ConcurrentLinkedQueue<E> newConcurrentLinkedQueue( Iterable<? extends E> elements) { if (elements instanceof Collection) { return new ConcurrentLinkedQueue<E>(Collections2.cast(elements)); } ConcurrentLinkedQueue<E> queue = new ConcurrentLinkedQueue<E>(); Iterables.addAll(queue, elements); return queue; }
/** * Creates a {@code LinkedBlockingDeque} with a capacity of {@link Integer#MAX_VALUE}, containing * the elements of the specified iterable, in the order they are returned by the iterable's * iterator. * * @since 12.0 */ @GwtIncompatible // LinkedBlockingDeque public static <E> LinkedBlockingDeque<E> newLinkedBlockingDeque(Iterable<? extends E> elements) { if (elements instanceof Collection) { return new LinkedBlockingDeque<E>(Collections2.cast(elements)); } LinkedBlockingDeque<E> deque = new LinkedBlockingDeque<E>(); Iterables.addAll(deque, elements); return deque; }
/** * Creates a {@code LinkedBlockingQueue} with a capacity of {@link Integer#MAX_VALUE}, containing * the elements of the specified iterable, in the order they are returned by the iterable's * iterator. * * @param elements the elements that the queue should contain, in order * @return a new {@code LinkedBlockingQueue} containing those elements */ @GwtIncompatible // LinkedBlockingQueue public static <E> LinkedBlockingQueue<E> newLinkedBlockingQueue(Iterable<? extends E> elements) { if (elements instanceof Collection) { return new LinkedBlockingQueue<E>(Collections2.cast(elements)); } LinkedBlockingQueue<E> queue = new LinkedBlockingQueue<E>(); Iterables.addAll(queue, elements); return queue; }
/** * Creates a {@code PriorityBlockingQueue} containing the given elements. * * <p><b>Note:</b> If the specified iterable is a {@code SortedSet} or a {@code PriorityQueue}, * this priority queue will be ordered according to the same ordering. * * @since 11.0 (requires that {@code E} be {@code Comparable} since 15.0). */ @GwtIncompatible // PriorityBlockingQueue public static <E extends Comparable> PriorityBlockingQueue<E> newPriorityBlockingQueue( Iterable<? extends E> elements) { if (elements instanceof Collection) { return new PriorityBlockingQueue<E>(Collections2.cast(elements)); } PriorityBlockingQueue<E> queue = new PriorityBlockingQueue<E>(); Iterables.addAll(queue, elements); return queue; }
/** * Creates a new {@code LinkedHashMultiset} containing the specified elements. * * <p>This implementation is highly efficient when {@code elements} is itself a {@link Multiset}. * * @param elements the elements that the multiset should contain */ public static <E> LinkedHashMultiset<E> create(Iterable<? extends E> elements) { LinkedHashMultiset<E> multiset = create(Multisets.inferDistinctElements(elements)); Iterables.addAll(multiset, elements); return multiset; }
@Override @CanIgnoreReturnValue public boolean addAll(Collection<? extends E> collection) { int size = collection.size(); if (size >= maxSize) { clear(); return Iterables.addAll(this, Iterables.skip(collection, size - maxSize)); } return standardAddAll(collection); }
public void testAddAllToList() { List<String> alreadyThere = newArrayList("already", "there"); List<String> freshlyAdded = newArrayList("freshly", "added"); boolean changed = Iterables.addAll(alreadyThere, freshlyAdded); assertThat(alreadyThere).containsExactly("already", "there", "freshly", "added").inOrder(); assertTrue(changed); }