org.xshare.base.iterator
Class ReverseIterator

java.lang.Object
  |
  +--org.xshare.base.iterator.ReverseIterator
All Implemented Interfaces:
java.util.Iterator
Direct Known Subclasses:
ListReverseIterator

public class ReverseIterator
extends java.lang.Object
implements java.util.Iterator

Iterator which returns the elements of a given iterator in reverse order.

Notes On The Implemenation

  1. The remove() method is not supported.
  2. Creating an instance of this iterator copies all elements of the source iteration to an internal cache. After returning an element via next() it is removed from the cache.

Version:
$Revision: 1.4 $
Author:
Oliver Fischer

Constructor Summary
ReverseIterator(java.util.Iterator pSourceIterator)
          Creates a new instance for a given iteration.
ReverseIterator(java.util.List pSourceList)
          Deprecated. If you need a reversing iterator for a List, then use the ListReverseIterator instead. This constructor will be removed with version 1.
 
Method Summary
 boolean hasNext()
          Checks if there are elements to return left.
 java.lang.Object next()
          Returns the next element of the iteration.
 void remove()
          This operation is not supported by this iterator, since it works on an internal copy of the original iteration.
protected  void setUsedIterator(java.util.Iterator pIterator)
          Deprecated. Don't used it. Will be removed with version 1.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReverseIterator

public ReverseIterator(java.util.Iterator pSourceIterator)
Creates a new instance for a given iteration. The created iterator will return the last element of the source iteration first.

Hint: This iterator copies all elements of the source iterator into a private collection instance and operates on this collection instead on the original iteration. This can increase you memory consumption if you create an instance of a huge iteration.

Parameters:
pSourceIterator - an Iterator value

ReverseIterator

public ReverseIterator(java.util.List pSourceList)
Deprecated. If you need a reversing iterator for a List, then use the ListReverseIterator instead. This constructor will be removed with version 1.

Method Detail

remove

public void remove()
This operation is not supported by this iterator, since it works on an internal copy of the original iteration.

Specified by:
remove in interface java.util.Iterator

next

public java.lang.Object next()
Returns the next element of the iteration.

Specified by:
next in interface java.util.Iterator
Returns:
an Object object, representing the next object to return.

hasNext

public boolean hasNext()
Checks if there are elements to return left.

Specified by:
hasNext in interface java.util.Iterator
Returns:
a boolean value which is true if there are more elements. Otherwiese false is returned.

setUsedIterator

protected void setUsedIterator(java.util.Iterator pIterator)
Deprecated. Don't used it. Will be removed with version 1.



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