1 16 17 package org.apache.commons.jexl.util; 18 19 20 21 import java.util.Iterator ; 22 import java.util.NoSuchElementException ; 23 import java.lang.reflect.Array ; 24 25 26 45 public class ArrayIterator implements Iterator { 46 49 private final Object array; 50 51 54 private int pos; 55 56 59 private final int size; 60 61 66 public ArrayIterator(Object arr) { 67 72 73 if (!arr.getClass().isArray()) { 74 throw new IllegalArgumentException ("Programmer error :" 75 + " internal ArrayIterator invoked w/o array"); 76 } 77 78 array = arr; 79 pos = 0; 80 size = Array.getLength(array); 81 } 82 83 88 public Object next() { 89 if (pos < size) { 90 return Array.get(array, pos++); 91 } 92 93 96 97 throw new NoSuchElementException ("No more elements: " + pos 98 + " / " + size); 99 } 100 101 106 public boolean hasNext() { 107 return (pos < size); 108 } 109 110 113 public void remove() { 114 throw new UnsupportedOperationException (); 115 } 116 } 117 | Popular Tags |