1 28 29 package com.idaremedia.antx.helpers; 30 31 import java.lang.reflect.Array ; 32 import java.util.Enumeration ; 33 import java.util.Iterator ; 34 import java.util.NoSuchElementException ; 35 36 46 47 public class ArrayIterator extends NoRemoveIteratorSkeleton implements Iterator , Enumeration 48 { 49 private final Object m_array; 50 private final int m_len; 51 private int m_i; 52 53 57 public ArrayIterator(Object array) 58 { 59 if (array==null || !array.getClass().isArray()) { 60 throw new IllegalArgumentException ("ctor- nonzro ary reqd"); 61 } 62 m_array = array; 63 m_len = Array.getLength(array); 64 } 65 66 67 70 public boolean hasNext() 71 { 72 return m_i < m_len; 73 } 74 75 76 79 public final boolean hasMoreElements() 80 { 81 return hasNext(); 82 } 83 84 85 89 public Object next() 90 { 91 if (m_i>=m_len) { 92 throw new NoSuchElementException (); 93 } 94 return Array.get(m_array,m_i++); 95 } 96 97 98 101 public final Object nextElement() 102 { 103 return next(); 104 } 105 106 107 111 public int nextIndex() 112 { 113 return (m_i>=m_len) ? m_len : m_i; 114 } 115 116 117 121 public void remove() 122 { 123 throw new UnsupportedOperationException ("Cannot remove slot from Java array"); 124 } 125 } 126 127 128 | Popular Tags |