Small code cleanup.
[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 39 /**
3b196926 40 * Should mimic the List<E> add(int index, E value) method
55c0c363
JB
41 * @param index [description]
42 * @param value [description]
df73e07c 43 * @return [description]
01bad5b3 44 */
54c717d4 45 public void addIter(int index, E value) {
01bad5b3
JB
46 ListIterator<E> iter = list.listIterator();
47 int i = 0;
54c717d4
JB
48 // go to the element at index + 1
49 while (iter.hasNext() && i <= index) {
01bad5b3
JB
50 iter.next();
51 i++;
52 }
01bad5b3
JB
53 iter.add(value);
54 }
55
54c717d4
JB
56 //FIXME: replace parameter by the list of objects to add
57 public void addNelements(int index, int Nelements) {
01bad5b3
JB
58 ListIterator<E> iter = list.listIterator();
59 int i = 0;
54c717d4
JB
60 // go to the element at index + 1
61 while (iter.hasNext() && i <= index) {
01bad5b3
JB
62 iter.next();
63 i++;
64 }
01bad5b3
JB
65 for (int j = 0; j < Nelements; j++) {
66 iter.add((E)new Object());
67 }
68 }
69
70}