001 /*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License"). You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2006-2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.backends.jeb;
028
029 import java.util.Iterator;
030 import java.util.NoSuchElementException;
031
032 /**
033 * Implements an iterator over a range of entry IDs.
034 */
035 public class IndexIteratorRange implements Iterator<EntryID>
036 {
037 /**
038 * The upper bound of the range.
039 */
040 private long highID;
041
042 /**
043 * The current position of the iterator in the range.
044 */
045 private long currentID;
046
047
048
049 /**
050 * Constructs a range iterator from lower and upper bounds.
051 *
052 * @param lowID The lower bound.
053 * @param highID The upper bound.
054 */
055 public IndexIteratorRange(long lowID, long highID)
056 {
057 this.currentID = lowID;
058 this.highID = highID;
059 }
060
061
062
063 /**
064 * Returns <tt>true</tt> if the iteration has more elements. (In other words,
065 * returns <tt>true</tt> if <tt>next</tt> would return an element rather than
066 * throwing an exception.)
067 *
068 * @return <tt>true</tt> if the iterator has more elements.
069 */
070 public boolean hasNext()
071 {
072 return currentID <= highID;
073 }
074
075
076
077 /**
078 * Returns the next element in the iteration. Calling this method repeatedly
079 * until the {@link #hasNext()} method returns false will return each element
080 * in the underlying collection exactly once.
081 *
082 * @return the next element in the iteration.
083 * @throws java.util.NoSuchElementException
084 * iteration has no more elements.
085 */
086 public EntryID next() throws NoSuchElementException
087 {
088 if (currentID <= highID)
089 {
090 return new EntryID(currentID++);
091 }
092 else
093 {
094 throw new NoSuchElementException();
095 }
096 }
097
098
099
100 /**
101 * Removes from the underlying collection the last element returned by the
102 * iterator (optional operation). This method can be called only once per
103 * call to <tt>next</tt>. The behavior of an iterator is unspecified if the
104 * underlying collection is modified while the iteration is in progress in any
105 * way other than by calling this method.
106 *
107 * @throws UnsupportedOperationException if the <tt>remove</tt> operation is
108 * not supported by this Iterator.
109 */
110 public void remove() throws UnsupportedOperationException
111 {
112 throw new UnsupportedOperationException();
113 }
114 }