/** make a new iterator, which is our elements that pass the filter */ @Override public FilterIterator<T> filterKeep( Predicate<T> f ) { return new FilterIterator<>( f, this ); }
/** make a new iterator, which is our elements that pass the filter */ @Override public FilterIterator<T> filterKeep( Predicate<T> f ) { return new FilterIterator<>( f, this ); }
/** make a new iterator, which is our elements that do not pass the filter */ @Override public FilterIterator<T> filterDrop( final Predicate<T> f ) { return new FilterIterator<>( f.negate(), this ); }
/** make a new iterator, which is our elements that do not pass the filter */ @Override public FilterIterator<T> filterDrop( final Predicate<T> f ) { return new FilterIterator<>( f.negate(), this ); }
/** * <p> * Answer an iterator over the elements of iterator a that are not members of iterator b. * As a side-effect, iterator b will be closed. * </p> * * @param a An iterator that will be filtered by rejecting the elements of b * @param b A closable iterator * @return The iteration of elements in a but not in b. */ public static <T> ClosableIterator<T> butNot( final ClosableIterator<T> a, final ClosableIterator<? extends T> b ) { return new FilterIterator<>( reject( b ), a ); }
/** * <p> * Answer an iterator over the elements of iterator a that are not members of iterator b. * As a side-effect, iterator b will be closed. * </p> * * @param a An iterator that will be filtered by rejecting the elements of b * @param b A closable iterator * @return The iteration of elements in a but not in b. */ public static <T> ClosableIterator<T> butNot( final ClosableIterator<T> a, final ClosableIterator<? extends T> b ) { return new FilterIterator<>( reject( b ), a ); }
public void testFilterIterator() { Iterator<String> i = iteratorOfStrings( "there's an a in some animals" ); Iterator<String> it = new FilterIterator<>( containsA, i ); assertEquals( listOfStrings( "an a animals" ), iteratorToList( it ) ); }
public void testFilterIterator() { Iterator<String> i = iteratorOfStrings( "there's an a in some animals" ); Iterator<String> it = new FilterIterator<>( containsA, i ); assertEquals( listOfStrings( "an a animals" ), iteratorToList( it ) ); }