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