exo2: make use of a DP conposite.
[Project_POO.git] / exo2 / ListExtension.java
1 import java.util.List;
2 import java.util.ListIterator;
3 import java.util.AbstractList;
4
5 public class ListExtension<E> extends AbstractList<E> {
6 private List<E> list;
7
8 public ListExtension() {
9 setList(null);
10 }
11
12 public ListExtension(List<E> l) {
13 setList(l);
14 }
15
16 /**
17 * [setList description]
18 * @param l [description]
19 */
20 public void setList(List<E> l) {
21 list = l;
22 }
23
24 /**
25 * [getList description]
26 * @return [description]
27 */
28 public List<E> getList() {
29 return list;
30 }
31
32 /**
33 * [get description]
34 * @param index [description]
35 * @return [description]
36 */
37 public E get(int index) {
38 return list.get(index);
39 }
40
41 /**
42 * [size description]
43 * @return [description]
44 */
45 public int size() {
46 return list.size();
47 }
48
49 public boolean add(E e) {
50 return list.add(e);
51 }
52
53 /**
54 * Should mimic the List<E> add(int index, E value) method
55 * @param index [description]
56 * @param value [description]
57 * @return [description]
58 */
59 public void add(int index, E value) {
60 ListIterator<E> iter = list.listIterator();
61 int i = 0;
62 // go to the element at index + 1
63 while (iter.hasNext() && i <= index) {
64 iter.next();
65 i++;
66 }
67 iter.add(value);
68 }
69
70 //FIXME: replace parameter by the list of objects to add
71 public void addNelements(int index, int Nelements) {
72 ListIterator<E> iter = list.listIterator();
73 int i = 0;
74 // go to the element at index + 1
75 while (iter.hasNext() && i <= index) {
76 iter.next();
77 i++;
78 }
79 for (int j = 0; j < Nelements; j++) {
80 iter.add((E)new Object());
81 }
82 }
83
84 }