From: Jérôme Benoit Date: Mon, 16 Apr 2018 19:36:23 +0000 (+0200) Subject: exo2: make use of a DP conposite. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e1499f74d5264f2205c54bf9b1a4c66fd447a844;p=Project_POO.git exo2: make use of a DP conposite. Signed-off-by: Jérôme Benoit --- diff --git a/exo2/ListExtension.java b/exo2/ListExtension.java index 20e9fb2..df2c789 100644 --- a/exo2/ListExtension.java +++ b/exo2/ListExtension.java @@ -1,7 +1,8 @@ import java.util.List; import java.util.ListIterator; +import java.util.AbstractList; -public class ListExtension { +public class ListExtension extends AbstractList { private List list; public ListExtension() { @@ -28,21 +29,34 @@ public class ListExtension { return list; } - public boolean add(E e) { - return list.add(e); + /** + * [get description] + * @param index [description] + * @return [description] + */ + public E get(int index) { + return list.get(index); } + /** + * [size description] + * @return [description] + */ public int size() { return list.size(); } + public boolean add(E e) { + return list.add(e); + } + /** * Should mimic the List add(int index, E value) method * @param index [description] * @param value [description] * @return [description] */ - public void addIter(int index, E value) { + public void add(int index, E value) { ListIterator iter = list.listIterator(); int i = 0; // go to the element at index + 1 diff --git a/exo2/Main.java b/exo2/Main.java index 2fbf94f..75c828b 100644 --- a/exo2/Main.java +++ b/exo2/Main.java @@ -19,7 +19,7 @@ class Main { long startTime = System.nanoTime(); // for (int i = 0; i < 100000; i++) { - // array.addIter(array.size() / 2, i); + // array.add(array.size() / 2, i); // } array.addNelements(array.size() / 2, 100000); long stopTime = System.nanoTime(); @@ -29,7 +29,7 @@ class Main { startTime = System.nanoTime(); // for (int i = 0; i < 100000; i++) { - // list.addIter(list.size() / 2, i); + // list.add(list.size() / 2, i); // } list.addNelements(list.size() / 2, 100000); stopTime = System.nanoTime();