1 19 package org.netbeans.modules.javacore.jmiimpl.javamodel; 20 21 import java.util.List ; 22 import java.util.Iterator ; 23 import java.util.ListIterator ; 24 import java.util.ArrayList ; 25 import java.util.AbstractList ; 26 import java.util.Collection ; 27 import org.netbeans.jmi.javamodel.JavaClass; 28 29 30 public class NotifierList implements List { 31 32 private List innerList; 33 private ChangeNotificationListener notificationListener; 34 35 public NotifierList(List innerList, ChangeNotificationListener notificationListener) { 36 setInnerList(innerList); 37 setNotificationListener(notificationListener); 38 } 39 40 public NotifierList(List innerList) { 41 setInnerList(innerList); 42 setNotificationListener(null); 43 } 44 45 public void setInnerList(List innerList) { 46 this.innerList = innerList; 47 } 48 49 public void setNotificationListener(ChangeNotificationListener notificationListener) { 50 this.notificationListener = notificationListener; 51 } 52 53 private void notifyChange(boolean add, Object o) { 54 if (notificationListener != null) 55 notificationListener.notifyChange(add, o); 56 } 57 58 private void notifyChange(boolean add, Collection c) { 59 if (notificationListener != null) 60 notificationListener.notifyChange(add, c); 61 } 62 63 65 public boolean remove(Object obj) { 66 boolean result = innerList.remove(obj); 67 if (result) 68 notifyChange(false, obj); 69 return result; 70 } 71 72 public Object set(int param, Object obj) { 73 Object result = innerList.set(param, obj); 74 notifyChange(true, obj); 75 if (result != null) 76 notifyChange(false, result); 77 return result; 78 } 79 80 public Object remove(int param) { 81 Object result = innerList.remove(param); 82 if (result != null) 83 notifyChange(false, result); 84 return result; 85 } 86 87 public void add(int param, Object obj) { 88 innerList.add(param, obj); 89 notifyChange(true, obj); 90 } 91 92 public boolean add(Object obj) { 93 boolean result = innerList.add(obj); 94 notifyChange(true, obj); 95 return result; 96 } 97 98 public ListIterator listIterator(int param) { 99 return new NotifierListIterator(innerList.listIterator(param)); 100 } 101 102 public Iterator iterator() { 103 return new NotifierListIterator(innerList.listIterator()); 104 } 105 106 public ListIterator listIterator() { 107 return new NotifierListIterator(innerList.listIterator()); 108 } 109 110 public List subList(int param, int param1) { 111 return new NotifierList(innerList.subList(param, param1), notificationListener); 112 } 113 114 public boolean contains(Object obj) { 115 return innerList.contains(obj); 116 } 117 118 public boolean containsAll(Collection collection) { 119 return innerList.containsAll(collection); 120 } 121 122 public boolean addAll(Collection c) { 123 boolean result = innerList.addAll(c); 124 if (result) { 125 notifyChange(true, c); 126 } 127 return result; 128 } 129 130 public void clear() { 131 notifyChange(false, null); 133 innerList.clear(); 134 } 135 136 public boolean isEmpty() { 137 return innerList.isEmpty(); 138 } 139 140 public boolean removeAll(Collection c) { 141 notifyChange(false, null); 143 return innerList.removeAll(c); 144 } 145 146 public boolean retainAll(Collection c) { 147 notifyChange(false, null); 149 return innerList.retainAll(c); 150 } 151 152 public int size() { 153 return innerList.size(); 154 } 155 156 public Object [] toArray() { 157 return innerList.toArray(); 158 } 159 160 public Object [] toArray(Object [] a) { 161 return innerList.toArray(a); 162 } 163 164 public boolean addAll(int index, Collection c) { 165 boolean result = innerList.addAll(index, c); 166 if (result) { 167 notifyChange(true, c); 168 } 169 return result; 170 } 171 172 public Object get(int index) { 173 return innerList.get(index); 174 } 175 176 public int indexOf(Object o) { 177 return innerList.indexOf(o); 178 } 179 180 public int lastIndexOf(Object o) { 181 return innerList.lastIndexOf(o); 182 } 183 184 class NotifierListIterator implements ListIterator { 186 187 private Object lastRead; 188 private ListIterator innerIterator; 189 190 NotifierListIterator(ListIterator iterator) { 191 this.innerIterator = iterator; 192 } 193 194 public void remove() { 195 innerIterator.remove(); 196 if (lastRead != null) 197 notifyChange(false, lastRead); 198 } 199 200 public void add(Object obj) { 201 innerIterator.add(obj); 202 notifyChange(true, obj); 203 } 204 205 public void set(Object obj) { 206 innerIterator.set(obj); 207 notifyChange(true, obj); 208 if (lastRead != null) 209 notifyChange(false, lastRead); 210 } 211 212 public boolean hasNext() { 213 return innerIterator.hasNext(); 214 } 215 216 public boolean hasPrevious() { 217 return innerIterator.hasPrevious(); 218 } 219 220 public Object next() { 221 return lastRead = innerIterator.next(); 222 } 223 224 public int nextIndex() { 225 return innerIterator.nextIndex(); 226 } 227 228 public Object previous() { 229 return lastRead = innerIterator.previous(); 230 } 231 232 public int previousIndex() { 233 return innerIterator.previousIndex(); 234 } 235 } 236 } 237 | Popular Tags |