1 22 23 package com.sosnoski.util; 24 25 import java.util.Iterator ; 26 import java.util.NoSuchElementException ; 27 28 36 37 public class WrappedArrayIterator implements Iterator 38 { 39 40 protected Object [] m_array; 41 42 43 protected int m_offset; 44 45 46 protected int m_last; 47 48 55 56 private WrappedArrayIterator(Object [] array, int start, int end) { 57 m_array = array; 58 m_offset = start; 59 m_last = end; 60 } 61 62 68 69 public boolean hasNext() { 70 return m_offset != m_last; 71 } 72 73 79 80 public Object next() { 81 if (m_offset != m_last) { 82 Object result = m_array[m_offset]; 83 m_offset = (m_offset+1) % m_array.length; 84 return result; 85 } else { 86 throw new NoSuchElementException (); 87 } 88 } 89 90 96 97 public void remove() { 98 throw new UnsupportedOperationException (); 99 } 100 101 111 112 public static Iterator buildIterator(Object [] array, int start, int end) { 113 if (array == null || start == end) { 114 return ArrayRangeIterator.EMPTY_ITERATOR; 115 } else { 116 return new WrappedArrayIterator(array, start, end); 117 } 118 } 119 } 120 | Popular Tags |