|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.xshare.base.iterator.helpers.CountingIterator
Wraps a given iterator and counts the via next()
returned elements. Since this method is only a proxy for
the real iteration, all the method calls are delegated
to the underlying iteration. Hence the behavior is not
well defined - it depends on the behavior of the real
iterator.
You have an iteration with some elements. You should print a list and the number of printed elements at the end of the list.
private printUsersSortedByName(Iterator source) { CountingIterator cItr = new CountingIterator(source); while (cItr.hasNext()) { System.out.println("Element: " + cItr.next()); } System.out.println("Printed " + cItr.getObjectCount() + " elements."); }
Field Summary | |
protected int |
objectCount
|
protected java.util.Iterator |
sourceIterator
|
Constructor Summary | |
CountingIterator(java.util.Iterator pSourceIterator)
|
Method Summary | |
int |
getObjectCount()
Returns the number of elements of the underlying iterator returned via next() . |
boolean |
hasNext()
Checks by delegating this method call to the underlying iteration, if there are more elements to return by next() or not. |
java.lang.Object |
next()
Returns the next element which is returned by the Iterator.next() method of the underlying
iterator .
|
void |
remove()
Calls the Iterator.remove() method of the
underlying iterator .
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int objectCount
protected java.util.Iterator sourceIterator
Constructor Detail |
public CountingIterator(java.util.Iterator pSourceIterator)
Method Detail |
public void remove()
Iterator.remove()
method of the
underlying iterator
.
There is no definite behavior of this
method, since this method call is only delegated.
To know if this operation is supported
or not, you must know the behavior of the underlying iterator.
remove
in interface java.util.Iterator
public java.lang.Object next()
Iterator.next()
method of the underlying
iterator
.
There is no definite behavior of this
method, since this method call is only delegated.
next
in interface java.util.Iterator
Object
representing the next object
of the underlying iteration returned by the
Iterator.next()
of the
wrapped iterator
.public boolean hasNext()
next()
or not.
hasNext
in interface java.util.Iterator
boolean
value, which is true
if
there are still elements to return. Otherwise false
is
returned.next()
public int getObjectCount()
iterator
returned via next()
.
int
value containing the number of
elements returned via next()
.next()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |