/** * Filters FileStatuses in an array and returns a list * * @param input An array of FileStatuses * @param filter A required filter to filter the array * @return A list of FileStatuses */ public static List<FileStatus> filterFileStatuses(FileStatus[] input, FileStatusFilter filter) { if (input == null) return null; return filterFileStatuses(Iterators.forArray(input), filter); }
RegionInfo region = Iterators.get(regions.iterator(), regionIndex);
int minThreshold = comConf.getDateTieredIncomingWindowMin(); PeekingIterator<Pair<HStoreFile, Long>> it = Iterators.peekingIterator(storefileMaxTimestampPairs.iterator()); while (it.hasNext()) { if (window.compareToTimestamp(oldestToCompact) < 0) {
/** * 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); }
Iterators.peekingIterator(positiveRanges.iterator()); final Cut<C> firstComplementRangeLowerBound; if (complementLowerBoundWindow.contains(Cut.<C>belowAll()) firstComplementRangeLowerBound = positiveItr.next().upperBound; } else { return Iterators.emptyIterator();
/** * A sensible definition of {@link #addAll} in terms of {@link #add}. If you * override {@link #add}, you may wish to override {@link #addAll} to forward * to this implementation. * * @since 7.0 */ protected boolean standardAddAll(Collection<? extends E> collection) { return Iterators.addAll(this, collection.iterator()); }
/** * A sensible definition of {@link #clear} in terms of the {@code iterator} * method of {@link #entrySet}. In many cases, you may wish to override * {@link #clear} to forward to this implementation. * * @since 7.0 */ protected void standardClear() { Iterators.clear(entrySet().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(); }
private ListIterator<? extends F> backingIterator() { return Iterators.cast(backingIterator); }
/** * Returns {@code true} if any element in {@code iterable} satisfies the predicate. * * <p><b>{@code Stream} equivalent:</b> {@link Stream#anyMatch}. */ public static <T> boolean any(Iterable<T> iterable, Predicate<? super T> predicate) { return Iterators.any(iterable.iterator(), predicate); }
/** * Returns {@code true} if every element in {@code iterable} satisfies the predicate. If {@code * iterable} is empty, {@code true} is returned. * * <p><b>{@code Stream} equivalent:</b> {@link Stream#allMatch}. */ public static <T> boolean all(Iterable<T> iterable, Predicate<? super T> predicate) { return Iterators.all(iterable.iterator(), predicate); }
@Override public Iterator<T> iterator() { final Iterator<T> iterator = iterable.iterator(); Iterators.advance(iterator, numberToSkip); /* * We can't just return the iterator because an immediate call to its * remove() method would remove one of the skipped elements instead of * throwing an IllegalStateException. */ return new Iterator<T>() { boolean atStart = true; @Override public boolean hasNext() { return iterator.hasNext(); } @Override public T next() { T result = iterator.next(); atStart = false; // not called if next() fails return result; } @Override public void remove() { checkRemove(!atStart); iterator.remove(); } }; }
/** * 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); } }
&& complementLowerBoundWindow.upperBoundType() == BoundType.CLOSED; final PeekingIterator<Range<C>> positiveItr = Iterators.peekingIterator( positiveRangesByUpperBound .headMap(startingPoint, inclusive) } else if (!complementLowerBoundWindow.contains(Cut.<C>belowAll()) || positiveRangesByLowerBound.containsKey(Cut.belowAll())) { return Iterators.emptyIterator(); } else { cut = positiveRangesByLowerBound.higherKey(Cut.<C>belowAll());
private static <E> ArrayList<E> toArrayList(Collection<E> c) { // Avoid calling ArrayList(Collection), which may call back into toArray. ArrayList<E> result = new ArrayList<E>(c.size()); Iterators.addAll(result, c.iterator()); return result; }
@Override public void clear() { Iterators.clear(entryIterator()); } }
/** Iterates in the order {@link #nodeU()}, {@link #nodeV()}. */ @Override public final UnmodifiableIterator<N> iterator() { return Iterators.forArray(nodeU, nodeV); }
public MergingIterator( Iterable<? extends Iterator<? extends T>> iterators, final Comparator<? super T> itemComparator) { // A comparator that's used by the heap, allowing the heap // to be sorted based on the top of each iterator. Comparator<PeekingIterator<T>> heapComparator = new Comparator<PeekingIterator<T>>() { @Override public int compare(PeekingIterator<T> o1, PeekingIterator<T> o2) { return itemComparator.compare(o1.peek(), o2.peek()); } }; queue = new PriorityQueue<PeekingIterator<T>>(2, heapComparator); for (Iterator<? extends T> iterator : iterators) { if (iterator.hasNext()) { queue.add(Iterators.peekingIterator(iterator)); } } }
/** * Returns the element at the specified position in an iterable. * * <p><b>{@code Stream} equivalent:</b> {@code stream.skip(position).findFirst().get()} * (throws {@code NoSuchElementException} if out of bounds) * * @param position position of the element to return * @return the element at the specified position in {@code iterable} * @throws IndexOutOfBoundsException if {@code position} is negative or * greater than or equal to the size of {@code iterable} */ public static <T> T get(Iterable<T> iterable, int position) { checkNotNull(iterable); return (iterable instanceof List) ? ((List<T>) iterable).get(position) : Iterators.get(iterable.iterator(), position); }
private static <E> ArrayList<E> toArrayList(Collection<E> c) { // Avoid calling ArrayList(Collection), which may call back into toArray. ArrayList<E> result = new ArrayList<E>(c.size()); Iterators.addAll(result, c.iterator()); return result; }