Class FilteredIterator<T>

java.lang.Object
overit.geocall.util.FilteredIterator<T>
Type Parameters:
T - The type of elements returned by this iterator
All Implemented Interfaces:
Iterator

public abstract class FilteredIterator<T> extends Object implements Iterator
This class implements an Iterator over a collection that iterates only on valid elements. The method that checks the validity is custombizable.
  • Field Details

    • _i

      protected Iterator<T> _i
    • _cached

      protected boolean _cached
    • _cache

      protected T _cache
  • Constructor Details

    • FilteredIterator

      public FilteredIterator(Iterator<T> i)
      Creates a FilteredIterator starting from the Iterator passed as parameter
      Parameters:
      i - The iterator used for the creation of the FilteredIterator
  • Method Details

    • valid

      protected abstract boolean valid(T t)
    • hasNext

      public boolean hasNext()
      Returns true if the FilteredIterator has more valid elements. The validity of the elements is verified with the valid(java.lang.Object) method. The search for the valid element is performed only if it is not cached yet.
      Specified by:
      hasNext in interface Iterator<T>
      Returns:
      true if the iteration has more elements, false otherwise
    • next

      public T next()
      Returns the next valid element in the iteration. The search for the valid element is performed only if it is not cached yet (for example by the method hasNext()).
      Specified by:
      next in interface Iterator<T>
      Returns:
      The next valid element in the iteration
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<T>