1 package cz.cuni.amis.utils.collections;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6 import java.util.List;
7 import java.util.ListIterator;
8 import java.util.Set;
9
10
11
12
13
14
15 public class ObservableList<E> extends ObservableCollection<E> implements List<E> {
16
17 protected List<E> l = null;
18
19 public ObservableList(List<E> list) {
20 super(list);
21 l = list;
22 }
23
24
25
26
27
28 public List<E> getList() {
29 return l;
30 }
31
32
33 @Override
34 public boolean addAll(int index, Collection<? extends E> c) {
35 notifyPreAdd(c);
36 boolean ret = l.addAll(index, c);
37 notifyPostAdd(c);
38 return ret;
39 }
40
41 @Override
42 public boolean addAll(Collection<? extends E> c) {
43 return addAll(l.size(), c);
44 }
45
46 @Override
47 public void clear() {
48 List<Object> copy = new ArrayList<Object>(col);
49 notifyPreRemove(copy);
50 l.clear();
51 notifyPostRemove(copy);
52 }
53
54
55
56 @Override
57 public E get(int index) {
58 return l.get(index);
59 }
60
61 @Override
62 public E set(int index, E element) {
63 return l.set(index, element);
64 }
65
66 @Override
67 public void add(int index, E element) {
68 Set<E> add = Collections.singleton(element);
69 notifyPreAdd(add);
70 l.add(index, element);
71 notifyPostAdd(add);
72 }
73
74 @Override
75 public E remove(int index) {
76 Set<E> toRem = Collections.singleton(l.get(index));
77 notifyPreRemove(toRem);
78 E rem = l.remove(index);
79 notifyPostRemove(Collections.singleton(rem));
80 return rem;
81 }
82
83 @Override
84 public int indexOf(Object o) {
85 return l.indexOf(o);
86 }
87
88 @Override
89 public int lastIndexOf(Object o) {
90 return lastIndexOf(o);
91 }
92
93 @Override
94 public ListIterator<E> listIterator() {
95 return l.listIterator();
96 }
97
98 @Override
99 public ListIterator<E> listIterator(int index) {
100 return l.listIterator(index);
101 }
102
103 @Override
104 public List<E> subList(int fromIndex, int toIndex) {
105 return l.subList(fromIndex, toIndex);
106 }
107 }