@Override public Iterator<T> iterator() { return Iterators.filter(unfiltered.iterator(), retainIfTrue); }
@Override public Iterator<E> iterator() { return Iterators.filter(unfiltered.iterator(), predicate); }
@Override Iterator<Entry<K, V>> entryIterator() { return Iterators.filter(unfiltered.entrySet().iterator(), entryPredicate); }
/** * Wraps another iterator and throws away nulls. */ public static <T> Iterator<T> removeNull(final Iterator<T> itr) { return com.google.common.collect.Iterators.filter(itr, Predicates.notNull()); }
private Iterator<Row> getRowsIterator(List<Row> rows) { if (rows == null) return null; return Iterators.filter(rows.iterator(), new Predicate<Row>() { @Override public boolean apply(@Nullable Row row) { // The hasOnlyTombstones(x) call below ultimately calls Column.isMarkedForDelete(x) return !(row == null || row.cf == null || row.cf.isMarkedForDelete() || row.cf.hasOnlyTombstones(nowMillis)); } }); }
@Override public UnmodifiableIterator<E> iterator() { return Iterators.filter(unfiltered.iterator(), predicate); }
@Override Iterator<Entry<K, V>> descendingEntryIterator() { return Iterators.filter(unfiltered.descendingMap().entrySet().iterator(), entryPredicate); }
public PartitionChunk<T> getChunk(final int partitionNum) { final Iterator<PartitionChunk<T>> retVal = Iterators.filter( holderSet.iterator(), input -> input.getChunkNumber() == partitionNum ); return retVal.hasNext() ? retVal.next() : null; }
@Override protected Iterator<Integer> newTargetIterator() { return Iterators.filter(list.iterator(), isEven); } }.test();
public <RetType> FunctionalIterator<RetType> keep(Function<T, RetType> fn) { return new FunctionalIterator<>(Iterators.filter(Iterators.transform(delegate, fn), Predicates.notNull())); }
public FunctionalIterator<T> filter(Predicate<T> pred) { return new FunctionalIterator<>(Iterators.filter(delegate, pred)); }
public RowIterator(Closeable table, ResultScanner rows, byte[] columnFamilyBytes) { this.table = table; this.columnFamilyBytes = Arrays.copyOf(columnFamilyBytes, columnFamilyBytes.length); this.rows = Iterators.filter(rows.iterator(), result -> null != result && null != result.getRow()); }
@Override public Iterator<Message> iterator() { return Iterators.filter(messages.iterator(), e -> !e.getFilterOut()); } }
/** * Returns a view of {@code unfiltered} containing all elements that are of the type {@code * desiredType}. */ @SuppressWarnings("unchecked") // can cast to <T> because non-Ts are removed @GwtIncompatible // Class.isInstance public static <T> UnmodifiableIterator<T> filter(Iterator<?> unfiltered, Class<T> desiredType) { return (UnmodifiableIterator<T>) filter(unfiltered, instanceOf(desiredType)); }
@Override public Iterator<E> descendingIterator() { return Iterators.filter(unfiltered().descendingIterator(), predicate); }
public void testFilterSimple() { Iterator<String> unfiltered = Lists.newArrayList("foo", "bar").iterator(); Iterator<String> filtered = Iterators.filter(unfiltered, Predicates.equalTo("foo")); List<String> expected = Collections.singletonList("foo"); List<String> actual = Lists.newArrayList(filtered); assertEquals(expected, actual); }
public void testFilterMatchAll() { Iterator<String> unfiltered = Lists.newArrayList("foo", "bar").iterator(); Iterator<String> filtered = Iterators.filter(unfiltered, Predicates.alwaysTrue()); List<String> expected = Lists.newArrayList("foo", "bar"); List<String> actual = Lists.newArrayList(filtered); assertEquals(expected, actual); }
/** * Returns a view of {@code unfiltered} containing all elements that are of the type {@code * desiredType}. */ @SuppressWarnings("unchecked") // can cast to <T> because non-Ts are removed @GwtIncompatible // Class.isInstance public static <T> UnmodifiableIterator<T> filter(Iterator<?> unfiltered, Class<T> desiredType) { return (UnmodifiableIterator<T>) filter(unfiltered, instanceOf(desiredType)); }
public void testFilterNothing() { Iterator<String> unfiltered = Collections.<String>emptyList().iterator(); Iterator<String> filtered = Iterators.filter( unfiltered, new Predicate<String>() { @Override public boolean apply(String s) { throw new AssertionFailedError("Should never be evaluated"); } }); List<String> expected = Collections.emptyList(); List<String> actual = Lists.newArrayList(filtered); assertEquals(expected, actual); }
public void testFilterNoMatch() { Iterator<String> unfiltered = Lists.newArrayList("foo", "bar").iterator(); Iterator<String> filtered = Iterators.filter(unfiltered, Predicates.alwaysFalse()); List<String> expected = Collections.emptyList(); List<String> actual = Lists.newArrayList(filtered); assertEquals(expected, actual); }