1 20 package org.enhydra.barracuda.plankton.data; 21 22 import java.io.*; 23 import java.util.*; 24 25 30 public class PArrayList extends AbstractPData implements PList { 31 32 private List list = new ArrayList(); 33 34 35 44 public void setStore(List ilist) { 45 list = ilist; 46 } 47 48 53 public void add(int index, Object el) { 54 if (el!=null && el instanceof PData) { 59 PData pdata = (PData) el; 60 if (pdata.isInheritParents() && pdata.getParent()==null) pdata.setParent(this); } 63 64 list.add(index, el); 66 } 67 68 72 public boolean add(Object el) { 73 if (el!=null && el instanceof PData) { 78 PData pdata = (PData) el; 79 if (pdata.isInheritParents() && pdata.getParent()==null) pdata.setParent(this); } 82 83 return list.add(el); 85 } 86 87 92 public boolean addAll(Collection c) { 93 if (c!=null) { 99 Iterator it = c.iterator(); 100 while (it.hasNext()) { 101 Object el = it.next(); 102 if (el!=null && el instanceof PData) { 103 PData pdata = (PData) el; 104 if (pdata.isInheritParents() && pdata.getParent()==null) pdata.setParent(this); } 107 } 108 } 109 110 return list.addAll(c); 112 } 113 114 118 public boolean addAll(int index, Collection c) { 119 if (c!=null) { 125 Iterator it = c.iterator(); 126 while (it.hasNext()) { 127 Object el = it.next(); 128 if (el!=null && el instanceof PData) { 129 PData pdata = (PData) el; 130 if (pdata.isInheritParents() && pdata.getParent()==null) pdata.setParent(this); } 133 } 134 } 135 136 return list.addAll(index, c); 138 } 139 140 143 public void clear() { 144 Iterator it = list.iterator(); 146 while (it.hasNext()) { 147 Object el = it.next(); 148 if (el!=null && el instanceof PData) { 149 PData pdata = (PData) el; 150 if (pdata.isInheritParents() && pdata.getParent()==this) pdata.setParent(null); } 153 } 154 155 list.clear(); 157 } 158 159 162 public boolean contains(Object el) { 163 return list.contains(el); 164 } 165 166 170 public boolean containsAll(Collection c) { 171 if (list.size()<1) return c.size()<1; 177 178 return list.containsAll(c); 180 } 181 182 185 public Object get(int index) { 186 return list.get(index); 187 } 188 189 193 public int indexOf(Object el) { 194 return list.indexOf(el); 195 } 196 197 200 public boolean isEmpty() { 201 return list.isEmpty(); 202 } 203 204 207 public Iterator iterator() { 208 return list.iterator(); 209 } 210 211 215 public int lastIndexOf(Object el) { 216 return list.lastIndexOf(el); 217 } 218 219 222 public ListIterator listIterator() { 223 return list.listIterator(); 224 } 225 226 230 public ListIterator listIterator(int index) { 231 return listIterator(index); 232 } 233 234 238 public Object remove(int index) { 239 Object curEl = list.get(index); 245 if (curEl!=null && curEl instanceof PData) { 246 PData pdata = (PData) curEl; 247 if (pdata.isInheritParents() && pdata.getParent()==this) pdata.setParent(null); } 250 251 return list.remove(index); 253 } 254 255 259 public boolean remove(Object el) { 260 if (el!=null && el instanceof PData && list.contains(el)) { 266 PData pdata = (PData) el; 267 if (pdata.isInheritParents() && pdata.getParent()==this) pdata.setParent(null); } 270 271 return list.remove(el); 273 } 274 275 279 public boolean removeAll(Collection c) { 280 if (c!=null) { 286 Iterator it = c.iterator(); 287 while (it.hasNext()) { 288 Object el = it.next(); 289 if (el!=null && el instanceof PData) { 290 PData pdata = (PData) el; 291 if (pdata.isInheritParents() && pdata.getParent()==this) pdata.setParent(null); } 294 } 295 } 296 297 return list.removeAll(c); 299 } 300 301 305 public boolean retainAll(Collection c) { 306 if (c!=null) { 312 Iterator it = list.iterator(); 313 while (it.hasNext()) { 314 Object el = it.next(); 315 if (el!=null && el instanceof PData) { 316 PData pdata = (PData) el; 317 if (pdata.isInheritParents() && pdata.getParent()==this && !(c.contains(el))) pdata.setParent(null); } 320 } 321 } 322 323 return list.retainAll(c); 325 } 326 327 331 public Object set(int index, Object el) { 332 Object curEl = list.get(index); 338 if (curEl!=null && curEl instanceof PData) { 339 PData pdata = (PData) curEl; 340 if (pdata.isInheritParents() && pdata.getParent()==this) pdata.setParent(null); } 343 344 if (el!=null && el instanceof PData) { 349 PData pdata = (PData) el; 350 if (pdata.isInheritParents() && pdata.getParent()==null) pdata.setParent(this); } 353 354 return list.set(index, el); 356 } 357 358 361 public int size() { 362 return list.size(); 363 } 364 365 369 public List subList(int fromIndex, int toIndex){ 370 return list.subList(fromIndex, toIndex); 371 } 372 373 377 public Object [] toArray() { 378 return list.toArray(); 379 } 380 381 386 public Object [] toArray(Object [] a) { 387 return list.toArray(a); 388 } 389 390 391 398 public Object clone() { 399 try { 400 PArrayList pal = (PArrayList) super.clone(); 401 pal.list = new ArrayList(list); 402 return pal; 403 } catch (CloneNotSupportedException e) { 404 throw new InternalError (); 406 } 407 } 408 409 410 420 public boolean equals(Object obj) { 421 if (obj==null) return false; 422 if (obj==this) return true; 423 if (!(obj instanceof PList)) return false; 424 PList pl = (PList) obj; 425 if (this.size()!=pl.size()) return false; 426 return (this.containsAll(pl)); 427 } 428 429 432 public int hashCode() { 433 return list.hashCode(); 434 } 435 436 437 439 440 441 } 442 | Popular Tags |