/*
 * Copyright 2013
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at:
 * 
 * http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 * implied. See the License for the specific language governing 
 * permissions and limitations under the License.
 */
package org.openntf.domino.iterators;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.openntf.domino.NoteCollection;
import org.openntf.domino.utils.DominoUtils;

// TODO: Auto-generated Javadoc
/**
 * The Class DocumentIterator.
 */
public class NoteIterator extends AbstractDominoIterator<String> {
	/** The Constant log_. */
	private static final Logger log_ = Logger.getLogger(NoteIterator.class.getName());

	/** The index_. */
	private int index_ = 0;

	/** The id array_. */
	private int[] idArray_;

	/**
	 * Instantiates a new document iterator.
	 * 
	 * @param collection
	 *            the collection
	 */
	public NoteIterator(final NoteCollection collection) {
		super(collection);
		setIdArray(getCollectionIds(collection));
	}

	/**
	 * Gets the collection ids.
	 * 
	 * @param nc
	 *            the nc
	 * @return the collection ids
	 */
	protected int[] getCollectionIds(final NoteCollection nc) {
		int[] result = null;
		if (nc != null) {
			try {
				if (nc.getCount() > 0) {
					result = nc.getNoteIDs();
				} else {
					if (log_.isLoggable(Level.FINER)) {
						log_.log(Level.FINER, "Attempted to get id array of empty NoteCollection");
					}
				}
			} catch (Throwable t) {
				DominoUtils.handleException(t);
			}
		} else {
			if (log_.isLoggable(Level.WARNING)) {
				log_.log(Level.WARNING, "Attempted to iterate over null NoteCollection");
			}
		}
		return result;
	}

	/**
	 * Gets the id array.
	 * 
	 * @return the id array
	 */
	protected int[] getIdArray() {
		return idArray_;
	}

	/**
	 * Gets the index.
	 * 
	 * @return the index
	 */
	protected int getIndex() {
		return index_;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Iterator#hasNext()
	 */
	public boolean hasNext() {
		return !((getIndex() + 1) > getIdArray().length);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Iterator#next()
	 */
	public String next() {
		String result = null;
		if (hasNext()) {
			result = Integer.toHexString(getIdArray()[getIndex()]);
			setIndex(getIndex() + 1);
		}
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Iterator#remove()
	 */
	public void remove() {
		// NOOP
	}

	/**
	 * Sets the id array.
	 * 
	 * @param idArray
	 *            the new id array
	 */
	protected void setIdArray(final int[] idArray) {
		idArray_ = idArray;
	}

	/**
	 * Sets the index.
	 * 
	 * @param index
	 *            the new index
	 */
	protected void setIndex(final int index) {
		index_ = index;
	}
}

@@ -2334,24 +2334,113 @@
 hasNext() %7B%0A
+%09%09if (getIdArray() == null) %7B%0A%09%09%09// Most commonly if no match found%0A%09%09%09return false;%0A%09%09%7D%0A
 %09%09return !((

Fix also applied to NoteIterator