1 16 package org.apache.commons.collections.iterators; 17 18 import java.util.ListIterator ; 19 import java.util.NoSuchElementException ; 20 21 import org.apache.commons.collections.ResettableListIterator; 22 23 43 public class ObjectArrayListIterator extends ObjectArrayIterator 44 implements ListIterator , ResettableListIterator { 45 46 52 protected int lastItemIndex = -1; 53 54 60 public ObjectArrayListIterator() { 61 super(); 62 } 63 64 71 public ObjectArrayListIterator(Object [] array) { 72 super(array); 73 } 74 75 84 public ObjectArrayListIterator(Object [] array, int start) { 85 super(array, start); 86 } 87 88 99 public ObjectArrayListIterator(Object [] array, int start, int end) { 100 super(array, start, end); 101 } 102 103 106 111 public boolean hasPrevious() { 112 return (this.index > this.startIndex); 113 } 114 115 121 public Object previous() { 122 if (hasPrevious() == false) { 123 throw new NoSuchElementException (); 124 } 125 this.lastItemIndex = --this.index; 126 return this.array[this.index]; 127 } 128 129 135 public Object next() { 136 if (hasNext() == false) { 137 throw new NoSuchElementException (); 138 } 139 this.lastItemIndex = this.index; 140 return this.array[this.index++]; 141 } 142 143 148 public int nextIndex() { 149 return this.index - this.startIndex; 150 } 151 152 157 public int previousIndex() { 158 return this.index - this.startIndex - 1; 159 } 160 161 168 public void add(Object obj) { 169 throw new UnsupportedOperationException ("add() method is not supported"); 170 } 171 172 189 public void set(Object obj) { 190 if (this.lastItemIndex == -1) { 191 throw new IllegalStateException ("must call next() or previous() before a call to set()"); 192 } 193 194 this.array[this.lastItemIndex] = obj; 195 } 196 197 200 public void reset() { 201 super.reset(); 202 this.lastItemIndex = -1; 203 } 204 205 } 206 | Popular Tags |