tribble.repository
Class AbstractDocumentIterator<DocType extends AbstractDocument>

java.lang.Object
  extended by tribble.repository.AbstractDocumentIterator<DocType>
All Implemented Interfaces:
java.io.Closeable, java.util.Iterator<DocType>, DocumentIterator<DocType>

public class AbstractDocumentIterator<DocType extends AbstractDocument>
extends java.lang.Object
implements DocumentIterator<DocType>

Abstract generic document set iterator.

A repository document set iterator is an iterator over a collection of repository documents. Such a set is typically the result of a query performed on a repository.

Note: This requires Java 1.5 or later.

Source code:
http://david.tribble.com/src/java/tribble/repository/AbstractDocumentIterator.java
Documentation:
http://david.tribble.com/docs/tribble/repository/AbstractDocumentIterator.html

Since:
2008-04-09
Version:
API 2.0, $Revision: 1.2 $ $Date: 2008/04/09 17:01:20 $
Author:
David R. Tribble (david@tribble.com)
Copyright ©2008 by David R. Tribble, all rights reserved.
Permission is granted to any person or entity except those designated by the United States Department of State as a terrorist or terrorist government or agency, to use and distribute this source code provided that the original copyright notice remains present and unaltered.
See Also:
AbstractDocument

Field Summary
protected  java.util.ArrayList<DocType> m_docs
          Document set.
protected  int m_modCount
          Modification serial number.
protected  int m_pos
          Current document index within the set.
 
Constructor Summary
protected AbstractDocumentIterator(java.util.ArrayList<DocType> docs)
          Constructor.
 
Method Summary
 void close()
          Close this document set iterator.
 boolean hasNext()
          Determine if there are any more documents within the document set.
 DocType next()
          Retrieve the next document within the document set.
 void remove()
          Remove the current document from the document set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_docs

protected java.util.ArrayList<DocType extends AbstractDocument> m_docs
Document set.


m_pos

protected int m_pos
Current document index within the set.


m_modCount

protected int m_modCount
Modification serial number.

Constructor Detail

AbstractDocumentIterator

protected AbstractDocumentIterator(java.util.ArrayList<DocType> docs)
Constructor.

Parameters:
docs - Parent list of documents for which this iterator was created.
Since:
API 2.0, 2008-04-09
Method Detail

close

public void close()
Close this document set iterator. Deallocates all resources associated with the document set. Any further use of this object will result in exceptions.

Note that this method does not throw any exceptions.

Note that this method to be called more than once.

Specified by:
close in interface java.io.Closeable
Specified by:
close in interface DocumentIterator<DocType extends AbstractDocument>
Since:
API 2.0, 2008-04-09

hasNext

public boolean hasNext()
Determine if there are any more documents within the document set.

Specified by:
hasNext in interface java.util.Iterator<DocType extends AbstractDocument>
Specified by:
hasNext in interface DocumentIterator<DocType extends AbstractDocument>
Returns:
True if one or more documents remain within the document set, false otherwise.
Throws:
java.io.IOException - Thrown if an error occurred while accessing the document iterator.
Since:
API 2.0, 2008-04-09

next

public DocType next()
Retrieve the next document within the document set. Also advances the iterator to the next document in the set.

Note that this method also removes the previous document from the document set, so calling remove() is not necessary. Note also that removed documents do not have their close() methods called, which could leave them in an unstable state. Callers of this method should therefore call the close() method for each document returned.

Specified by:
next in interface java.util.Iterator<DocType extends AbstractDocument>
Specified by:
next in interface DocumentIterator<DocType extends AbstractDocument>
Returns:
The next repository document in the set.
Since:
API 2.0, 2008-04-09

remove

public void remove()
            throws java.lang.UnsupportedOperationException,
                   java.lang.IllegalStateException
Remove the current document from the document set.

Note that calling this method is not necessary, since next() automatically removes each document it previously returned. Note also that removed documents do not have their close() methods called, which could leave them in an unstable state.

Specified by:
remove in interface java.util.Iterator<DocType extends AbstractDocument>
Specified by:
remove in interface DocumentIterator<DocType extends AbstractDocument>
Throws:
java.lang.UnsupportedOperationException - (unchecked) Thrown if this operation is not supported by this iterator.
java.lang.IllegalStateException - (unchecked) Thrown if next() has not been called, or if remove() has already been called on the same item in the set.
Since:
API 2.0, 2008-04-09