1 11 12 package org.eclipse.core.internal.databinding; 13 14 import java.util.List ; 15 import java.util.ListIterator ; 16 17 23 public class RandomAccessListIterator implements ListIterator { 24 private ListIterator delegate = null; 25 26 29 public RandomAccessListIterator(ListIterator iterator) { 30 this.delegate = iterator; 31 } 32 33 36 public RandomAccessListIterator(List list) { 37 if (list == null) { 38 throw new IllegalArgumentException ("list is null"); } 40 this.delegate = list.listIterator(); 41 } 42 43 46 public void add(Object arg0) { 47 delegate.add(arg0); 48 } 49 50 53 public boolean hasNext() { 54 return delegate.hasNext(); 55 } 56 57 60 public boolean hasPrevious() { 61 return delegate.hasPrevious(); 62 } 63 64 67 public Object next() { 68 return delegate.next(); 69 } 70 71 74 public int nextIndex() { 75 return delegate.nextIndex(); 76 } 77 78 81 public Object previous() { 82 return delegate.previous(); 83 } 84 85 88 public int previousIndex() { 89 return delegate.previousIndex(); 90 } 91 92 95 public void remove() { 96 delegate.remove(); 97 } 98 99 102 public void set(Object arg0) { 103 delegate.set(arg0); 104 } 105 106 115 public Object get(int index) { 116 if (delegate.nextIndex() == 0 && !delegate.hasNext()) { 117 throw new IndexOutOfBoundsException ("Request for element from empty list"); } 119 if (index < 0) { 120 throw new IndexOutOfBoundsException ("Request for negative element index"); } 122 123 while (nextIndex() < index && hasNext()) { 124 next(); 125 } 126 while (previousIndex() > index-1) { 127 previous(); 128 } 129 if (!hasNext()) { 130 throw new IndexOutOfBoundsException ("Request for element past end of list"); } 132 return next(); 133 } 134 135 } 136 | Popular Tags |