From e1499f74d5264f2205c54bf9b1a4c66fd447a844 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 16 Apr 2018 21:36:23 +0200 Subject: [PATCH] exo2: make use of a DP conposite. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- exo2/ListExtension.java | 22 ++++++++++++++++++---- exo2/Main.java | 4 ++-- 2 files changed, 20 insertions(+), 6 deletions(-) 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(); -- 2.34.1