001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.util; 020 021import java.util.Iterator; 022 023/** 024 * Iterator Implementation for a Object Array 025 */ 026public final class ArrayIterator implements Iterator { 027 028 private Object[] arr; 029 private int offset; 030 private int length; 031 032 /** 033 * constructor for the class 034 * @param arr Base Array 035 */ 036 public ArrayIterator(Object[] arr) { 037 this.arr=arr; 038 this.offset=0; 039 this.length=arr.length; 040 } 041 042 public ArrayIterator(Object[] arr, int offset, int length) { 043 this.arr=arr; 044 this.offset=offset; 045 this.length=offset+length; 046 if(this.length>arr.length)this.length=arr.length; 047 048 } 049 050 public ArrayIterator(Object[] arr, int offset) { 051 this.arr=arr; 052 this.offset=offset; 053 this.length=arr.length; 054 055 } 056 057 @Override 058 public void remove() { 059 throw new UnsupportedOperationException("this operation is not suppored"); 060 } 061 062 @Override 063 public boolean hasNext() { 064 return (length)>offset; 065 } 066 067 @Override 068 public Object next() { 069 return arr[offset++]; 070 } 071 072}