//============================================================================== // AbstractDocumentIterator.java //============================================================================== package tribble.archive; import java.io.IOException; import java.lang.Exception; import java.lang.UnsupportedOperationException; import java.lang.String; import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.NoSuchElementException; /******************************************************************************* * Abstract generic document set iterator. * *
* An archive document set iterator is an iterator over a collection of * archive documents. Such a set is typically the result of a query * performed on an archive. * *
* Note: This requires Java 1.5 or later. * * *
* Note that this method also removes the previous document from the document * set, so calling {@link #remove remove()} is not necessary. * Note also that removed documents do not have their * {@link ArchiveDocument#close close()} methods called, which could leave * them in an unstable state. * * @return * The next archive document in the set. * * @since API 2.0, 2008-04-03 */ //@Override public AbstractDocument next() { AbstractDocument doc; // Sanity checks if (m_set == null) throw new NoSuchElementException(); if (m_modCount != m_set.m_modCount) throw new ConcurrentModificationException(); if (m_pos >= m_set.size()) throw new NoSuchElementException(); // Remove the previous document from the set, // since it is no longer needed if (m_pos > 0) { m_set.m_modCount = ++m_modCount; m_set.m_docs.set(m_pos - 1, null); } // Get the next document and advance the pointer doc = m_set.m_docs.get(m_pos++); return doc; } /*************************************************************************** * Remove the current document from the document set. * *
* Note that calling this method is not necessary, since {@link #next} * automatically removes each document it previously returned. * Note also that removed documents do not have their * {@link ArchiveDocument#close close()} methods called, which could leave * them in an unstable state. * * @throws UnsupportedOperationException (unchecked) * Thrown if this operation is not supported by this iterator. * * @throws IllegalStateException (unchecked) * Thrown if {@link #next} has not been called, or if {@link #remove} has * already been called on the same item in the set. * * @since API 2.0, 2008-04-03 */ //@Override public void remove() throws UnsupportedOperationException, IllegalStateException { // Sanity checks if (m_set == null) throw new NoSuchElementException(); if (m_pos == 0) throw new IllegalStateException("next() not called yet"); if (m_modCount != m_set.m_modCount) throw new ConcurrentModificationException(); if (m_set.m_docs.get(m_pos) == null) throw new IllegalStateException("Document already removed"); // Remove the document from the document set m_set.m_modCount = ++m_modCount; m_set.m_docs.set(m_pos, null); } } // End AbstractDocumentIterator.java