Class FilterListIterator<E>

java.lang.Object
org.apache.commons.collections4.iterators.FilterListIterator<E>
All Implemented Interfaces:
Iterator<E>, ListIterator<E>

public class FilterListIterator<E> extends Object implements ListIterator<E>
Decorates another ListIterator using a predicate to filter elements.

This iterator decorates the underlying iterator, only allowing through those elements that match the specified Predicate.

Since:
2.0
  • Field Details

    • iterator

      private ListIterator<? extends E> iterator
      The iterator being used
    • predicate

      private Predicate<? super E> predicate
      The predicate being used
    • nextObject

      private E nextObject
      The value of the next (matching) object, when nextObjectSet is true.
    • nextObjectSet

      private boolean nextObjectSet
      Whether or not the nextObject has been set (possibly to null).
    • previousObject

      private E previousObject
      The value of the previous (matching) object, when previousObjectSet is true.
    • previousObjectSet

      private boolean previousObjectSet
      Whether or not the previousObject has been set (possibly to null).
    • nextIndex

      private int nextIndex
      The index of the element that would be returned by next().
  • Constructor Details

    • FilterListIterator

      public FilterListIterator()
      Constructs a new FilterListIterator that will not function until setListIterator and setPredicate are invoked.
    • FilterListIterator

      public FilterListIterator(ListIterator<? extends E> iterator)
      Constructs a new FilterListIterator that will not function until setPredicate is invoked.
      Parameters:
      iterator - the iterator to use
    • FilterListIterator

      public FilterListIterator(ListIterator<? extends E> iterator, Predicate<? super E> predicate)
      Constructs a new FilterListIterator.
      Parameters:
      iterator - the iterator to use
      predicate - the predicate to use
    • FilterListIterator

      public FilterListIterator(Predicate<? super E> predicate)
      Constructs a new FilterListIterator that will not function until setListIterator is invoked.
      Parameters:
      predicate - the predicate to use.
  • Method Details

    • add

      public void add(E o)
      Not supported.
      Specified by:
      add in interface ListIterator<E>
      Parameters:
      o - the element to insert
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<E>
      Specified by:
      hasNext in interface ListIterator<E>
    • hasPrevious

      public boolean hasPrevious()
      Specified by:
      hasPrevious in interface ListIterator<E>
    • next

      public E next()
      Specified by:
      next in interface Iterator<E>
      Specified by:
      next in interface ListIterator<E>
    • nextIndex

      public int nextIndex()
      Specified by:
      nextIndex in interface ListIterator<E>
    • previous

      public E previous()
      Specified by:
      previous in interface ListIterator<E>
    • previousIndex

      public int previousIndex()
      Specified by:
      previousIndex in interface ListIterator<E>
    • remove

      public void remove()
      Not supported.
      Specified by:
      remove in interface Iterator<E>
      Specified by:
      remove in interface ListIterator<E>
    • set

      public void set(E o)
      Not supported.
      Specified by:
      set in interface ListIterator<E>
      Parameters:
      o - the element with which to replace the last element returned by next or previous
    • getListIterator

      public ListIterator<? extends E> getListIterator()
      Gets the iterator this iterator is using.
      Returns:
      the iterator.
    • setListIterator

      public void setListIterator(ListIterator<? extends E> iterator)
      Sets the iterator for this iterator to use. If iteration has started, this effectively resets the iterator.
      Parameters:
      iterator - the iterator to use
    • getPredicate

      public Predicate<? super E> getPredicate()
      Gets the predicate this iterator is using.
      Returns:
      the predicate.
    • setPredicate

      public void setPredicate(Predicate<? super E> predicate)
      Sets the predicate this the iterator to use.
      Parameters:
      predicate - the transformer to use
    • clearNextObject

      private void clearNextObject()
    • setNextObject

      private boolean setNextObject()
    • clearPreviousObject

      private void clearPreviousObject()
    • setPreviousObject

      private boolean setPreviousObject()