1 10 package mondrian.util; 11 12 import java.util.Collection ; 13 import java.util.Iterator ; 14 import java.util.ListIterator ; 15 import java.util.List ; 16 import java.util.NoSuchElementException ; 17 18 37 public abstract class UnsupportedList<T> implements List <T> { 38 protected UnsupportedList() { 39 } 40 public boolean isEmpty() { 41 return (size() == 0); 42 } 43 44 public int size() { 45 throw new UnsupportedOperationException (getClass().getName()+".size"); 46 } 47 public T get(int index) { 48 throw new UnsupportedOperationException (getClass().getName()+".get"); 49 } 50 public T set(int index, T element) { 51 throw new UnsupportedOperationException (getClass().getName()+".set"); 52 } 53 54 public Object [] toArray() { 55 throw new UnsupportedOperationException (getClass().getName()+".toArray"); 56 } 57 58 public void add(int index, T element) { 59 throw new UnsupportedOperationException (getClass().getName()+".add"); 60 } 61 public T remove(int index) { 62 throw new UnsupportedOperationException (getClass().getName()+".remove"); 63 } 64 public int indexOf(Object o) { 65 throw new UnsupportedOperationException (getClass().getName()+".indexOf"); 66 } 67 public int lastIndexOf(Object o) { 68 throw new UnsupportedOperationException (getClass().getName()+".lastIndexOf"); 69 } 70 public List <T> subList(int fromIndex, int toIndex) { 71 throw new UnsupportedOperationException (getClass().getName()+".subList"); 72 } 73 public boolean contains(Object o) { 74 throw new UnsupportedOperationException (getClass().getName()+".contains"); 75 } 76 public <T> T[] toArray(T[] a) { 77 throw new UnsupportedOperationException (getClass().getName()+".toArray"); 78 } 79 public boolean add(T o) { 80 throw new UnsupportedOperationException (getClass().getName()+".add"); 81 } 82 public boolean remove(Object o) { 83 throw new UnsupportedOperationException (getClass().getName()+".remove"); 84 } 85 public boolean containsAll(Collection <?> c) { 86 throw new UnsupportedOperationException (getClass().getName()+".containsAll"); 87 } 88 public boolean addAll(Collection <? extends T> c) { 89 throw new UnsupportedOperationException (getClass().getName()+".addAll"); 90 } 91 public boolean addAll(int index, Collection <? extends T> c) { 92 throw new UnsupportedOperationException (getClass().getName()+".addAll"); 93 } 94 public boolean removeAll(Collection <?> c) { 95 throw new UnsupportedOperationException (getClass().getName()+".removeAll"); 96 } 97 public boolean retainAll(Collection <?> c) { 98 throw new UnsupportedOperationException (getClass().getName()+".retainAll"); 99 } 100 public void clear() { 101 throw new UnsupportedOperationException (getClass().getName()+".clear"); 102 } 103 public boolean equals(Object o) { 104 throw new UnsupportedOperationException (getClass().getName()+".equals"); 105 } 106 public int hashCode() { 107 throw new UnsupportedOperationException (getClass().getName()+".hashCode"); 108 } 109 public ListIterator <T> listIterator() { 110 throw new UnsupportedOperationException (getClass().getName()+".listIterator"); 111 } 112 public ListIterator <T> listIterator(int index) { 113 throw new UnsupportedOperationException (getClass().getName()+".listIterator"); 114 } 115 public Iterator <T> iterator() { 116 throw new UnsupportedOperationException (getClass().getName()+".iterator"); 117 } 118 119 protected class Itr implements Iterator <T> { 120 protected int cursor; 121 protected int lastRet; 122 123 public Itr() { 124 this.cursor = 0; 125 this.lastRet = -1; 126 } 127 128 public boolean hasNext() { 129 return (cursor != size()); 130 } 131 public T next() { 132 try { 133 T next = get(cursor); 134 lastRet = cursor++; 135 return next; 136 } catch(IndexOutOfBoundsException e) { 137 System.out.println("UnsupportedList.Itr.next: cursor=" +cursor); 138 System.out.println("UnsupportedList.Itr.next: size=" +size()); 139 throw new NoSuchElementException (); 140 } 141 } 142 public void remove() { 143 throw new UnsupportedOperationException (getClass().getName()+".remove"); 144 } 145 } 146 147 protected class ListItr extends Itr implements ListIterator <T> { 148 public ListItr(int index) { 149 this.cursor = index; 150 } 151 152 public boolean hasPrevious() { 153 return cursor != 0; 154 } 155 public T previous() { 156 try { 157 int i = cursor - 1; 158 T previous = get(i); 159 lastRet = cursor = i; 160 return previous; 161 } catch(IndexOutOfBoundsException e) { 162 throw new NoSuchElementException (); 163 } 164 } 165 166 public int nextIndex() { 167 return cursor; 168 } 169 170 public int previousIndex() { 171 return cursor-1; 172 } 173 174 public void set(T o) { 175 184 throw new UnsupportedOperationException (getClass().getName()+".set"); 185 } 186 187 public void add(T o) { 188 throw new UnsupportedOperationException (getClass().getName()+".add"); 189 } 190 } 191 } 192 | Popular Tags |