org.apache.stanbol.entityhub.servicesapi.util
Class FilteringIterator<T>

java.lang.Object
  extended by org.apache.stanbol.entityhub.servicesapi.util.AdaptingIterator<T,T>
      extended by org.apache.stanbol.entityhub.servicesapi.util.FilteringIterator<T>
Type Parameters:
T - the type of the elements
All Implemented Interfaces:
Iterator<T>

public class FilteringIterator<T>
extends AdaptingIterator<T,T>

Implementation of an Iterator that iterates over a filtered set of elements of its parent Iterator.

Note that Iterator.remove() only works as long as Iterator.hasNext() was not called to determine if there are further elements. The reason for that is, that in order to filter elements of the parent iterator Iterator.next() has to be called to check weather any further element is valid against the used FilteringIterator.Filter. This call to Iterator.next() causes the parent Iterator to switch to the next element, meaning that after that the remove() method would delete a different element. To avoid that this Iterator throws an IllegalStateException in such cases. If the parent Iterator does not support remove() at all an UnsupportedOperationException is thrown.

This implementation is based on the AdaptingIterator to avoid duplication of the filtering functionality also needed if an adapter can not convert a specific value of one type to an other.

Author:
Rupert Westenthaler

Nested Class Summary
static interface FilteringIterator.Filter<T>
          Interface used by the FilteringIterator to check if an element of the parent Iterator should be filtered or not.
 
Nested classes/interfaces inherited from class org.apache.stanbol.entityhub.servicesapi.util.AdaptingIterator
AdaptingIterator.Adapter<T,A>
 
Constructor Summary
FilteringIterator(Iterator<T> iterator, FilteringIterator.Filter<T> filter, Class<T> type)
           
 
Method Summary
 
Methods inherited from class org.apache.stanbol.entityhub.servicesapi.util.AdaptingIterator
hasNext, next, prepareNext, remove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilteringIterator

public FilteringIterator(Iterator<T> iterator,
                         FilteringIterator.Filter<T> filter,
                         Class<T> type)


Copyright © 2010-2013 The Apache Software Foundation. All Rights Reserved.