1 7 8 package java.util; 9 10 52 53 public abstract class AbstractSequentialList<E> extends AbstractList <E> { 54 58 protected AbstractSequentialList() { 59 } 60 61 73 public E get(int index) { 74 ListIterator <E> e = listIterator(index); 75 try { 76 return(e.next()); 77 } catch(NoSuchElementException exc) { 78 throw(new IndexOutOfBoundsException ("Index: "+index)); 79 } 80 } 81 82 110 public E set(int index, E element) { 111 ListIterator <E> e = listIterator(index); 112 try { 113 E oldVal = e.next(); 114 e.set(element); 115 return oldVal; 116 } catch(NoSuchElementException exc) { 117 throw(new IndexOutOfBoundsException ("Index: "+index)); 118 } 119 } 120 121 148 public void add(int index, E element) { 149 ListIterator <E> e = listIterator(index); 150 e.add(element); 151 } 152 153 172 public E remove(int index) { 173 ListIterator <E> e = listIterator(index); 174 E outCast; 175 try { 176 outCast = e.next(); 177 } catch(NoSuchElementException exc) { 178 throw(new IndexOutOfBoundsException ("Index: "+index)); 179 } 180 e.remove(); 181 return(outCast); 182 } 183 184 185 187 227 public boolean addAll(int index, Collection <? extends E> c) { 228 boolean modified = false; 229 ListIterator <E> e1 = listIterator(index); 230 Iterator <? extends E> e2 = c.iterator(); 231 while (e2.hasNext()) { 232 e1.add(e2.next()); 233 modified = true; 234 } 235 return modified; 236 } 237 238 239 241 249 public Iterator <E> iterator() { 250 return listIterator(); 251 } 252 253 262 public abstract ListIterator <E> listIterator(int index); 263 } 264 | Popular Tags |