@Override public Iterator<LogicalOperator> iterator() { return Iterators.forArray(getLeft(), getRight()); }
@Override public Iterator<LogicalOperator> iterator() { return Iterators.singletonIterator(input); }
@Override public Iterator<Map.Entry<String, V>> getRange(final int skip, final int take) { final Iterator<Map.Entry<String, byte[]>> entries = client.entries(); Iterators.advance(entries, skip); return Iterators.transform(Iterators.limit(entries, take), new Function<Map.Entry<String, byte[]>, Map.Entry<String, V>>() { @Nullable @Override public Map.Entry<String, V> apply(@Nullable Map.Entry<String, byte[]> input) { try { final V value = config.getSerializer().deserialize(input.getValue()); return new ImmutableEntry<>(input.getKey(), value); } catch (final IOException e) { throw new DrillRuntimeException(String.format("unable to deserialize value at key %s", input.getKey()), e); } } }); }
@Override public Iterator<T> iterator() { return Iterators.transform(fromCollection.iterator(), function); }
/** * Advances {@code iterator} {@code position + 1} times, returning the * element at the {@code position}th position or {@code defaultValue} * otherwise. * * @param position position of the element to return * @param defaultValue the default value to return if the iterator is empty * or if {@code position} is greater than the number of elements * remaining in {@code iterator} * @return the element at the specified position in {@code iterator} or * {@code defaultValue} if {@code iterator} produces fewer than * {@code position + 1} elements. * @throws IndexOutOfBoundsException if {@code position} is negative * @since 4.0 */ @Nullable public static <T> T get(Iterator<? extends T> iterator, int position, @Nullable T defaultValue) { checkNonnegative(position); advance(iterator, position); return getNext(iterator, defaultValue); }
/** * Concats a varargs array of iterators without making a defensive copy of the array. */ static <T> Iterator<T> concatNoDefensiveCopy(Iterator<? extends T>... inputs) { for (Iterator<? extends T> input : checkNotNull(inputs)) { checkNotNull(input); } return concat(consumingForArray(inputs)); }
@Override public Iterator<T> iterator() { return Iterators.unmodifiableIterator(iterable.iterator()); }
/** * Advances {@code iterator} {@code position + 1} times, returning the * element at the {@code position}th position. * * @param position position of the element to return * @return the element at the specified position in {@code iterator} * @throws IndexOutOfBoundsException if {@code position} is negative or * greater than or equal to the number of elements remaining in * {@code iterator} */ public static <T> T get(Iterator<T> iterator, int position) { checkNonnegative(position); int skipped = advance(iterator, position); if (!iterator.hasNext()) { throw new IndexOutOfBoundsException( "position (" + position + ") must be less than the number of elements that remained (" + skipped + ")"); } return iterator.next(); }
@Override public Iterator<T> iterator() { return Iterators.cycle(iterable); }
@Override public Iterator<T> iterator() { return Iterators.limit(iterable.iterator(), limitSize); }
/** * Returns the single element contained in {@code iterable}. * * <p><b>Java 8 users:</b> the {@code Stream} equivalent to this method is {@code * stream.collect(MoreCollectors.onlyElement())}. * * @throws NoSuchElementException if the iterable is empty * @throws IllegalArgumentException if the iterable contains multiple elements */ public static <T> T getOnlyElement(Iterable<T> iterable) { return Iterators.getOnlyElement(iterable.iterator()); }
Iterators.advance(iterator, numberToSkip);
@Override public Iterator<T> iterator() { return Iterators.concat( /* lazily generate the iterators on each input only as needed */ new AbstractIndexedListIterator<Iterator<? extends T>>(inputs.length) { @Override public Iterator<? extends T> get(int i) { return inputs[i].iterator(); } }); } };
@Override public Iterator<T> iterator() { return Iterators.transform(fromIterable.iterator(), function); }
/** * Returns the element at the specified position in an iterable or a default * value otherwise. * * <p><b>{@code Stream} equivalent:</b> * {@code stream.skip(position).findFirst().orElse(defaultValue)} * (returns the default value if the index is out of bounds) * * @param position position of the element to return * @param defaultValue the default value to return if {@code position} is * greater than or equal to the size of the iterable * @return the element at the specified position in {@code iterable} or * {@code defaultValue} if {@code iterable} contains fewer than * {@code position + 1} elements. * @throws IndexOutOfBoundsException if {@code position} is negative * @since 4.0 */ @Nullable public static <T> T get(Iterable<? extends T> iterable, int position, @Nullable T defaultValue) { checkNotNull(iterable); Iterators.checkNonnegative(position); if (iterable instanceof List) { List<? extends T> list = Lists.cast(iterable); return (position < list.size()) ? list.get(position) : defaultValue; } else { Iterator<? extends T> iterator = iterable.iterator(); Iterators.advance(iterator, position); return Iterators.getNext(iterator, defaultValue); } }
/** * Combines two iterators into a single iterator. The returned iterator * iterates across the elements in {@code a}, followed by the elements in * {@code b}. The source iterators are not polled until necessary. * * <p>The returned iterator supports {@code remove()} when the corresponding * input iterator supports it. */ public static <T> Iterator<T> concat(Iterator<? extends T> a, Iterator<? extends T> b) { checkNotNull(a); checkNotNull(b); return concat(consumingForArray(a, b)); }
@Override public Iterator<CompleteFileWork> iterator() { return Iterators.unmodifiableIterator(chunks.iterator()); } };
/** * Returns an iterator that cycles indefinitely over the provided elements. * * <p>The returned iterator supports {@code remove()}. After {@code remove()} * is called, subsequent cycles omit the removed * element, but {@code elements} does not change. The iterator's * {@code hasNext()} method returns {@code true} until all of the original * elements have been removed. * * <p><b>Warning:</b> Typical uses of the resulting iterator may produce an * infinite loop. You should use an explicit {@code break} or be certain that * you will eventually remove all the elements. */ @SafeVarargs public static <T> Iterator<T> cycle(T... elements) { return cycle(Lists.newArrayList(elements)); }