|
||||||||||
| 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
org.xshare.base.iterator.
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
Deprecated. |
protected java.util.Iterator |
sourceIterator
Deprecated. |
| Constructor Summary | |
CountingIterator(java.util.Iterator pSourceIterator)
Deprecated. |
|
| Method Summary | |
int |
getObjectCount()
Deprecated. Returns the number of elements of the underlying iterator returned via next(). |
boolean |
hasNext()
Deprecated. 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()
Deprecated. Returns the next element which is returned by the Iterator.next() method of the underlying
iterator.
|
void |
remove()
Deprecated. 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)
java.lang.NullPointerException - if the given Iterator
is null.| 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.Iteratorpublic 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.IteratorObject 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.Iteratorboolean 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 | |||||||||