org.xshare.base.iterator
Class OneElementIterator

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

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

Specialized Iterator implementation which wraps a single object with an Iterator, which can return only the given object and this only ones.

Example

 class Yacl {

  // Imagine that this method is specified by a interface and
  // have to provide this method... But you will never have
  // more than one single element to return.
  public Iterator getAllResultElements() {
      return new OneElementIterator(mySingleResultObject);
  }
 }
 

Notes On The Implementation

Version:
$Revision: 1.5 $
Author:
Oliver Fischer
See Also:
LimitedIterator

Constructor Summary
OneElementIterator(java.lang.Object pObject)
          Creates a new instance for a given element.
 
Method Summary
 boolean hasNext()
           
 java.lang.Object next()
           
 void remove()
          This operation is not supported for this type of iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OneElementIterator

public OneElementIterator(java.lang.Object pObject)
Creates a new instance for a given element. This instance will return this element ones.

Throws:
java.lang.NullPointerException - if the object to be maintained by this iterator is null.
Method Detail

remove

public void remove()
This operation is not supported for this type of iterator.

Specified by:
remove in interface java.util.Iterator
Throws:
java.lang.UnsupportedOperationException - if this method is called since it is not supported.

next

public java.lang.Object next()
Specified by:
next in interface java.util.Iterator

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator


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