exo2: make use of a DP conposite.
[Project_POO.git] / exo2 / ListExtension.java
CommitLineData
01bad5b3
JB
1import java.util.List;
2import java.util.ListIterator;
e1499f74 3import java.util.AbstractList;
01bad5b3 4
e1499f74 5public class ListExtension<E> extends AbstractList<E> {
01bad5b3
JB
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
e1499f74
JB
32 /**
33 * [get description]
34 * @param index [description]
35 * @return [description]
36 */
37 public E get(int index) {
38 return list.get(index);
01bad5b3
JB
39 }
40
e1499f74
JB
41 /**
42 * [size description]
43 * @return [description]
44 */
54c717d4
JB
45 public int size() {
46 return list.size();
47 }
48
e1499f74
JB
49 public boolean add(E e) {
50 return list.add(e);
51 }
52
01bad5b3 53 /**
3b196926 54 * Should mimic the List<E> add(int index, E value) method
55c0c363
JB
55 * @param index [description]
56 * @param value [description]
df73e07c 57 * @return [description]
01bad5b3 58 */
e1499f74 59 public void add(int index, E value) {
01bad5b3
JB
60 ListIterator<E> iter = list.listIterator();
61 int i = 0;
54c717d4
JB
62 // go to the element at index + 1
63 while (iter.hasNext() && i <= index) {
01bad5b3
JB
64 iter.next();
65 i++;
66 }
01bad5b3
JB
67 iter.add(value);
68 }
69
54c717d4
JB
70 //FIXME: replace parameter by the list of objects to add
71 public void addNelements(int index, int Nelements) {
01bad5b3
JB
72 ListIterator<E> iter = list.listIterator();
73 int i = 0;
54c717d4
JB
74 // go to the element at index + 1
75 while (iter.hasNext() && i <= index) {
01bad5b3
JB
76 iter.next();
77 i++;
78 }
01bad5b3
JB
79 for (int j = 0; j < Nelements; j++) {
80 iter.add((E)new Object());
81 }
82 }
83
84}