|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.xshare.base.iterator.LimitedIterator
Specialized iterator wrapper to limit the elements returned by another iteration.
public void printTopFive(PrintStream ps) { // Here I will wrap the iterator of a map - sorted // by the points of the players - to get max. 5 players Iterator i = new LimitedIterator(5, sortedPlayers.iterator()); while (i.hasNext()) { ps.println(i.next()); } }
OneElementIterator
Constructor Summary | |
LimitedIterator(int pMaxElements,
java.util.Iterator pSourceIterator)
Creates a new instance of this iterator which returns not more than a given number of elements. |
Method Summary | |
boolean |
hasNext()
Checks if there are more elements to return or not. |
java.lang.Object |
next()
Returns the next element of the underlying iteration. |
void |
remove()
Removes the last element returned by next()
from the underlaying iteration by forwarding the remove call
to it. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public LimitedIterator(int pMaxElements, java.util.Iterator pSourceIterator)
java.lang.IllegalArgumentException
- if the limit of objects
to return by this iterator is negativ
java.lang.NullPointerException
- if the source iterator is nullMethod Detail |
public void remove()
next()
from the underlaying iteration by forwarding the remove call
to it.
remove
in interface java.util.Iterator
java.lang.UnsupportedOperationException
- if the source iteration
doesn't support this method.public java.lang.Object next()
next
in interface java.util.Iterator
java.util.NoSuchElementException
- if there are no more elements
to return by this method. Use hasNext()
to check this.hasNext()
public boolean hasNext()
hasNext
in interface java.util.Iterator
boolean
value which is true
if there are more elements to return. Otherwise false
is returned.next()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |