1 22 23 package com.sosnoski.util; 24 25 import java.util.Iterator ; 26 import java.util.NoSuchElementException ; 27 28 35 36 public class ArrayRangeIterator implements Iterator 37 { 38 39 public static final ArrayRangeIterator EMPTY_ITERATOR = 40 new ArrayRangeIterator(null, 0, 0); 41 42 43 protected Object [] m_array; 44 45 46 protected int m_offset; 47 48 49 protected int m_limit; 50 51 58 59 private ArrayRangeIterator(Object [] array, int start, int limit) { 60 m_array = array; 61 m_offset = start; 62 m_limit = limit; 63 } 64 65 71 72 public boolean hasNext() { 73 return m_offset < m_limit; 74 } 75 76 82 83 public Object next() { 84 if (m_offset < m_limit) { 85 return m_array[m_offset++]; 86 } else { 87 throw new NoSuchElementException (); 88 } 89 } 90 91 97 98 public void remove() { 99 throw new UnsupportedOperationException (); 100 } 101 102 111 112 public static Iterator buildIterator(Object [] array, int start, int limit) { 113 if (array == null || start >= limit) { 114 return EMPTY_ITERATOR; 115 } else { 116 return new ArrayRangeIterator(array, start, limit); 117 } 118 } 119 } 120 | Popular Tags |