/** * Gets an iterator that filters another iterator. * <p> * The returned iterator will only return objects that match the specified * filtering predicate. * * @param iterator the iterator to use, not null * @param predicate the predicate to use as a filter, not null * @return a new filtered iterator * @throws NullPointerException if either parameter is null */ public static Iterator filteredIterator(Iterator iterator, Predicate predicate) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } return new FilterIterator(iterator, predicate); }
/** * Gets an iterator that filters another iterator. * <p> * The returned iterator will only return objects that match the specified * filtering predicate. * * @param iterator the iterator to use, not null * @param predicate the predicate to use as a filter, not null * @return a new filtered iterator * @throws NullPointerException if either parameter is null */ public static Iterator filteredIterator(Iterator iterator, Predicate predicate) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } return new FilterIterator(iterator, predicate); }
/** * Returns a FilterIterator that does not filter * any of its elements * * @param i the Iterator to "filter" * @return "filtered" iterator */ protected FilterIterator makePassThroughFilter(Iterator i) { Predicate pred = new Predicate() { public boolean evaluate(Object x) { return true; } }; return new FilterIterator(i,pred); }
/** * Returns a FilterIterator that blocks * all of its elements * * @param i the Iterator to "filter" * @return "filtered" iterator */ protected FilterIterator makeBlockAllFilter(Iterator i) { Predicate pred = new Predicate() { public boolean evaluate(Object x) { return false; } }; return new FilterIterator(i,pred); } }
/** * Test that when the iterator is changed, the hasNext method returns the * correct response for the new iterator. */ public void testSetIterator() { Iterator iter1 = Collections.singleton(new Object()).iterator(); Iterator iter2 = Collections.EMPTY_LIST.iterator(); FilterIterator filterIterator = new FilterIterator(iter1); filterIterator.setPredicate(TruePredicate.getInstance()); // this iterator has elements assertEquals(true, filterIterator.hasNext()); // this iterator has no elements filterIterator.setIterator(iter2); assertEquals(false, filterIterator.hasNext()); }
/** * Test that when the predicate is changed, the hasNext method returns the * correct response for the new predicate. */ public void testSetPredicate() { Iterator iter = Collections.singleton(null).iterator(); FilterIterator filterIterator = new FilterIterator(iter); filterIterator.setPredicate(TruePredicate.getInstance()); // this predicate matches assertEquals(true, filterIterator.hasNext()); // this predicate doesn't match filterIterator.setPredicate(NotNullPredicate.getInstance()); assertEquals(false, filterIterator.hasNext()); }
@SuppressWarnings("unchecked") public static <T> Iterator<T> filterIntoIterator( Iterator<T> iterator, final Criterion criterion ) { return new FilterIterator( iterator, new Predicate() { public boolean evaluate( Object value ) { return criterion.matches( value ); } } ); } }
private Itr iterator(int mode) { _iterated = true; // have to copy the entry set of _map to prevent concurrent mod errors IteratorChain chain = new IteratorChain(); if (_map != null) chain.addIterator(new ArrayList(_map.entrySet()).iterator()); chain.addIterator(new FilterIterator(itr(), this)); return new Itr(mode, chain); }
private Itr iterator(int mode) { _iterated = true; // have to copy the entry set of _map to prevent concurrent mod errors IteratorChain chain = new IteratorChain(); if (_map != null) chain.addIterator(new ArrayList(_map.entrySet()).iterator()); chain.addIterator(new FilterIterator(itr(), this)); return new Itr(mode, chain); }
private Itr iterator(int mode) { _iterated = true; // have to copy the entry set of _map to prevent concurrent mod errors IteratorChain chain = new IteratorChain(); if (_map != null) chain.addIterator(new ArrayList(_map.entrySet()).iterator()); chain.addIterator(new FilterIterator(itr(), this)); return new Itr(mode, chain); }
@SuppressWarnings("unchecked") @Override public void reset() throws IOException { super.reset(); nePhrases = new LinkedList<Chunk>(); neChunks = new FilterIterator(at.getChunks(), new NamedEntityPredicate()); }
@SuppressWarnings("unchecked") public Iterator<Literal> getText(IRI field) { return new FilterIterator(new TransformIterator(data.filter(uri, field, null), TRIPLE2OBJECT), PLAIN_LITERALS); } @SuppressWarnings("unchecked")
public Iterator iterator() { _iterated = true; IteratorChain chain = new IteratorChain(); chain.addIterator(new FilterIterator(itr(), this)); // note have to copy _ct.getAdded to prevent concurrent mod errors chain.addIterator(new ArrayList(_ct.getAdded()).iterator()); return new Itr(chain); }
public Iterator iterator() { _iterated = true; IteratorChain chain = new IteratorChain(); chain.addIterator(new FilterIterator(itr(), this)); // note have to copy _ct.getAdded to prevent concurrent mod errors chain.addIterator(new ArrayList(_ct.getAdded()).iterator()); return new Itr(chain); }
public Iterator iterator() { _iterated = true; IteratorChain chain = new IteratorChain(); chain.addIterator(new FilterIterator(itr(), this)); // note have to copy _ct.getAdded to prevent concurrent mod errors chain.addIterator(new ArrayList(_ct.getAdded()).iterator()); return new Itr(chain); }
public Iterator iterator() { _iterated = true; IteratorChain chain = new IteratorChain(); chain.addIterator(new FilterIterator(itr(), this)); // note have to copy _ct.getAdded to prevent concurrent mod errors chain.addIterator(new ArrayList(_ct.getAdded()).iterator()); return new Itr(chain); }
public EntryIterator(int type) { _type = type; _itr.addIterator(new FilterIterator(getView(pinnedMap), this)); _itr.addIterator(getView(cacheMap)); _itr.addIterator(getView(softMap)); }
public EntryIterator(int type) { _type = type; _itr.addIterator(new FilterIterator(getView(pinnedMap), this)); _itr.addIterator(getView(cacheMap)); _itr.addIterator(getView(softMap)); }
public EntryIterator(int type) { _type = type; _itr.addIterator(new FilterIterator(getView(pinnedMap), this)); _itr.addIterator(getView(cacheMap)); _itr.addIterator(getView(softMap)); }
public EntryIterator(int type) { _type = type; _itr.addIterator(new FilterIterator(getView(pinnedMap), this)); _itr.addIterator(getView(cacheMap)); _itr.addIterator(getView(softMap)); }