【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“ArrayIterator.java”一文,供大家参考学习!
/* -*- mode: Java; fill-column: 72 -*-
* The contents of this file are subject to the ClickBlocks Public
* License Version 1.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.clickblocks.org
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied, including, but not limited to, the implied warranties of
* merchantability, fitness for a particular purpose and
* non-infringement. See the License for the specific language
* governing rights and limitations under the License.
*
* ClickBlocks, the ClickBlocks logo and combinations thereof are
* trademarks of ClickBlocks, LLC in the United States and other
* countries.
*
* The Initial Developer of the Original Code is ClickBlocks, LLC.
* Portions created by ClickBlocks, LLC are Copyright (C) 2000.
* All Rights Reserved.
*/
/*
* $Log: ArrayIterator.java,v $
* Revision 1.2 2000/11/03 10:26:00 mgrand
* moved to clickblocks package structure.
*
* Revision 1.1.1.1 2000/10/30 01:37:45 mgrand
* reestablished local repository
*/
package org.clickblocks.util;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* An iterator that iterates over an array.
* @stereotype container
* @author Mark Grand
*/
public class ArrayIterator implements Iterator {
private Object[] array;
private int index;
/**
* constructor
* @param array The array to iterate over.
*/
public ArrayIterator(Object[] array) {
this.array = array;
index = 0;
} // constructor(Object[])
/**
* Return true if there are any more elements to iterate over.
*/
public boolean hasNext(){
return index<array.length;
} // hasNext()
/**
* Return the next element.
* @exception NoSuchElementException
* If there is no next element.
*/
public Object next(){
if (index>=array.length) {
throw new NoSuchElementException();
} // if
Object element = array[index];
index++;
return element;
} // next()
/**
* This implementation of <code>remove</code> just throws
* <code>UnsupportedOperationException</code>.
*/
public void remove(){
throw new UnsupportedOperationException();
} // remove()
} // class ArrayIterator
// LocalWords: ArrayIterator java clickblocks param hasNext
// LocalWords: NoSuchElementException UnsupportedOperationException