org.xshare.base.iterator.helpers
Class CountingIterator

java.lang.Object
  |
  +--org.xshare.base.iterator.helpers.CountingIterator
All Implemented Interfaces:
java.util.Iterator

Deprecated. Please replace this iterator with the one from the package org.xshare.base.iterator.

public class CountingIterator
extends java.lang.Object
implements java.util.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.

Example...

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.");
 }

Version:
$Revision: 1.5 $
Author:
Oliver Fischer

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

objectCount

protected int objectCount
Deprecated. 

sourceIterator

protected java.util.Iterator sourceIterator
Deprecated. 
Constructor Detail

CountingIterator

public CountingIterator(java.util.Iterator pSourceIterator)
Deprecated. 
Throws:
java.lang.NullPointerException - if the given Iterator is null.
Method Detail

remove

public void remove()
Deprecated. 
Calls the 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.

Specified by:
remove in interface java.util.Iterator

next

public java.lang.Object next()
Deprecated. 
Returns the next element which is returned by the Iterator.next() method of the underlying iterator. There is no definite behavior of this method, since this method call is only delegated.

Specified by:
next in interface java.util.Iterator
Returns:
an Object representing the next object of the underlying iteration returned by the Iterator.next() of the wrapped iterator.

hasNext

public boolean hasNext()
Deprecated. 
Checks by delegating this method call to the underlying iteration, if there are more elements to return by next() or not.

Specified by:
hasNext in interface java.util.Iterator
Returns:
a boolean value, which is true if there are still elements to return. Otherwise false is returned.
See Also:
next()

getObjectCount

public int getObjectCount()
Deprecated. 
Returns the number of elements of the underlying iterator returned via next().

Returns:
an int value containing the number of elements returned via next().
See Also:
next()


jKiska Base 0.2.1 Release Esche [http://jkiska.sourceforge.net]