public class FilterListIterator<E>
extends java.lang.Object
implements java.util.ListIterator<E>
ListIterator
using a predicate to filter elements.
This iterator decorates the underlying iterator, only allowing through
those elements that match the specified Predicate
.
Modifier and Type | Field and Description |
---|---|
private java.util.ListIterator<? extends E> |
iterator
The iterator being used
|
private int |
nextIndex
The index of the element that would be returned by
next() . |
private E |
nextObject
The value of the next (matching) object, when
nextObjectSet is true. |
private boolean |
nextObjectSet
Whether or not the
nextObject has been set
(possibly to null ). |
private Predicate<? super E> |
predicate
The predicate being used
|
private E |
previousObject
The value of the previous (matching) object, when
previousObjectSet is true. |
private boolean |
previousObjectSet
Whether or not the
previousObject has been set
(possibly to null ). |
Constructor and Description |
---|
FilterListIterator()
Constructs a new
FilterListIterator that will not function
until setListIterator
and setPredicate are invoked. |
FilterListIterator(java.util.ListIterator<? extends E> iterator)
Constructs a new
FilterListIterator that will not
function until setPredicate is invoked. |
FilterListIterator(java.util.ListIterator<? extends E> iterator,
Predicate<? super E> predicate)
Constructs a new
FilterListIterator . |
FilterListIterator(Predicate<? super E> predicate)
Constructs a new
FilterListIterator that will not function
until setListIterator is invoked. |
Modifier and Type | Method and Description |
---|---|
void |
add(E o)
Not supported.
|
private void |
clearNextObject() |
private void |
clearPreviousObject() |
java.util.ListIterator<? extends E> |
getListIterator()
Gets the iterator this iterator is using.
|
Predicate<? super E> |
getPredicate()
Gets the predicate this iterator is using.
|
boolean |
hasNext() |
boolean |
hasPrevious() |
E |
next() |
int |
nextIndex() |
E |
previous() |
int |
previousIndex() |
void |
remove()
Not supported.
|
void |
set(E o)
Not supported.
|
void |
setListIterator(java.util.ListIterator<? extends E> iterator)
Sets the iterator for this iterator to use.
|
private boolean |
setNextObject() |
void |
setPredicate(Predicate<? super E> predicate)
Sets the predicate this the iterator to use.
|
private boolean |
setPreviousObject() |
private java.util.ListIterator<? extends E> iterator
private E nextObject
nextObjectSet
is true.private boolean nextObjectSet
nextObject
has been set
(possibly to null
).private E previousObject
previousObjectSet
is true.private boolean previousObjectSet
previousObject
has been set
(possibly to null
).private int nextIndex
next()
.public FilterListIterator()
FilterListIterator
that will not function
until setListIterator
and setPredicate
are invoked.public FilterListIterator(java.util.ListIterator<? extends E> iterator)
FilterListIterator
that will not
function until setPredicate
is invoked.iterator
- the iterator to usepublic FilterListIterator(java.util.ListIterator<? extends E> iterator, Predicate<? super E> predicate)
FilterListIterator
.iterator
- the iterator to usepredicate
- the predicate to usepublic FilterListIterator(Predicate<? super E> predicate)
FilterListIterator
that will not function
until setListIterator
is invoked.predicate
- the predicate to use.public boolean hasNext()
public boolean hasPrevious()
hasPrevious
in interface java.util.ListIterator<E>
public E next()
public int nextIndex()
nextIndex
in interface java.util.ListIterator<E>
public int previousIndex()
previousIndex
in interface java.util.ListIterator<E>
public void remove()
public java.util.ListIterator<? extends E> getListIterator()
public void setListIterator(java.util.ListIterator<? extends E> iterator)
iterator
- the iterator to usepublic Predicate<? super E> getPredicate()
public void setPredicate(Predicate<? super E> predicate)
predicate
- the transformer to useprivate void clearNextObject()
private boolean setNextObject()
private void clearPreviousObject()
private boolean setPreviousObject()