From 050792fe019d049f1cf4ac89744b7eae6f32c424 Mon Sep 17 00:00:00 2001 From: Paul W Date: Wed, 11 Jan 2023 14:28:34 -0800 Subject: [PATCH 01/15] Added ArrayList with add() method --- .idea/vcs.xml | 6 + src/Main.java | 21 ++ src/edu/greenriver/sdev333/ArrayList.java | 271 ++++++++++++++++++++++ 3 files changed, 298 insertions(+) create mode 100644 .idea/vcs.xml create mode 100644 src/edu/greenriver/sdev333/ArrayList.java diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Main.java b/src/Main.java index 3e59c38..f3e42e7 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,5 +1,26 @@ +import edu.greenriver.sdev333.*; + public class Main { public static void main(String[] args) { + System.out.println("Hello world!"); + + List friends = new ArrayList<>(); + + System.out.println("initial size is " + friends.size()); + + friends.add("Jess"); + friends.add("Tina"); + friends.add("Josh"); + friends.add("Susan"); + friends.add("Dee"); + friends.add("Tyler"); + friends.add("Usman"); + friends.add("Rose"); + friends.add("Blanche"); + friends.add("Dorothy"); + friends.add("Sophia"); + + System.out.println("size is now " + friends.size()); } } \ No newline at end of file diff --git a/src/edu/greenriver/sdev333/ArrayList.java b/src/edu/greenriver/sdev333/ArrayList.java new file mode 100644 index 0000000..46fa38b --- /dev/null +++ b/src/edu/greenriver/sdev333/ArrayList.java @@ -0,0 +1,271 @@ +package edu.greenriver.sdev333; + +import java.util.Iterator; +import java.util.ListIterator; + +public class ArrayList implements List { + + // WE NEED FIELDS + + // one plain Java array + private ItemType[] data; + + // one int to keep track of size + // size is the number of spots used in the data array + // size is different than length + private int size; + + public ArrayList() { + size = 0; + data = (ItemType[]) new Object[10]; + } + + + + + /** + * Returns the number of items in this collection. + * + * @return the number of items in this collection + */ + @Override + public int size() { + return size; + } + + /** + * Returns true if this collection contains no items. + * + * @return true if this collection contains no items + */ + @Override + public boolean isEmpty() { + return false; + } + + /** + * Returns true if this collection contains the specified item. + * + * @param item items whose presence in this collection is to be tested + * @return true if this collection contains the specified item + * @throws NullPointerException if the specified item is null + * and this collection does not permit null items + */ + @Override + public boolean contains(ItemType item) { + return false; + } + + /** + * Returns an iterator over the elements in this collection. + * + * @return an Iterator over the elements in this collection + */ + @Override + public Iterator iterator() { + return null; + } + + /** + * Adds the specified item to the collection. + * + * @param item item to be added to the collection + * @throws NullPointerException if the specified item is null + * and this collection does not permit null items + */ + @Override + public void add(ItemType item) { + + data[size++] = item; + + // all of the above works until I run out of room when size becomes + // the same as length, I'm out of room + if (size == data.length) { + // resize up .... + + // Step 1 - create a temp array 2x size + ItemType[] temp = (ItemType[]) new Object[data.length * 2];; + + // Step 2 - copy arrayElements from data to temp + for (int i = 0; i < size; i++) { + temp[i] = data[i]; + } + + // Step 3 - point 'data' at temp array + data = temp; + } + + } + + /** + * Removes a single instance of the specified item from this collection, + * if it is present. + * + * @param item item to be removed from this collection, if present + * @throws NullPointerException if the specified item is null + * and this collection does not permit null items + */ + @Override + public void remove(ItemType item) { + + } + + /** + * Removes all items from this collection. + * The collection will be empty after this method returns. + */ + @Override + public void clear() { + + } + + /** + * Returns true if this collection contains all the items + * in the specified other collection. + * + * @param otherCollection collection to be checked for containment in this collection + * @return true if this collection contains all the items + * in the specified other collection + */ + @Override + public boolean containsAll(Collection otherCollection) { + return false; + } + + /** + * Adds all the items in this specified other collection to this collection. + * + * @param otherCollection collection containing items to be added to this collection + */ + @Override + public void addAll(Collection otherCollection) { + + } + + /** + * Removes all of this collection's items that are also contained in the + * specified other collection. After this call returns, this collection will + * contain no elements in common with the specified other collection. + * + * @param otherCollection collection containing elements to be removed + * from this collection + */ + @Override + public void removeAll(Collection otherCollection) { + + } + + /** + * Retains only the items in this collection that are contained in the + * specified other collection. In other words, removes from this collection + * all of its items that are not contained in the specified other collection + * + * @param otherCollection collection containing elements to be retained in + * this collection + */ + @Override + public void retainAll(Collection otherCollection) { + + } + + /** + * Returns the item at the specified position in this list + * + * @param index index of the item to return + * @return the item at the specified position in this list + * @throws IndexOutOfBoundsException if this index is out of range + * (index < 0 || index >= size()) + */ + @Override + public ItemType get(int index) { + return null; + } + + /** + * Replaces the item at the specified position in this list + * with the specified item + * + * @param index index of the item to replace + * @param item item to be stored at the specified position + * @throws NullPointerException if the specified item is null + * and this list does not permit null elements + * @throws IndexOutOfBoundsException if the index is out of range + * (index < 0 || index >= size()) + */ + @Override + public void set(int index, ItemType item) { + + } + + /** + * Inserts the specified item at the specified position in this list. + * Shifts the item currently at that position (if any) and any subsequent + * items to the right. + * + * @param index index at which the specified item is to be inserted + * @param item item to be inserted + * @throws NullPointerException if the specified item is null + * and this list does not permit null elements + * @throws IndexOutOfBoundsException if the index is out of range + * (index < 0 || index >= size()) + */ + @Override + public void add(int index, ItemType item) { + + } + + /** + * Removes the element at the specified position in this list. + * Shifts any subsequent items to the left. + * + * @param index the index of the item to be removed + * @throws IndexOutOfBoundsException if the index is out of range + * (index < 0 || index >= size()) + */ + @Override + public void remove(int index) { + + } + + /** + * Returns the index of the first occurrence of the specified item + * in this list, or -1 if this list does not contain the item. + * + * @param item the item to search for + * @return the index of the first occurrence of the specified item + * in this list, or -1 if this list does not contain the item + * @throws NullPointerException if the specified item is null and this + * list does not permit null items + */ + @Override + public int indexOf(ItemType item) { + return 0; + } + + /** + * Returns the index of the last occurrence of the specified item + * in this list, or -1 if this list does not contain the item. + * + * @param item the item to search for + * @return the index of the first occurrence of the specified item + * in this list, or -1 if this list does not contain the item + * @throws NullPointerException if the specified item is null and this + * list does not permit null items + */ + @Override + public int lastIndexOf(ItemType item) { + return 0; + } + + /** + * Returns a list iterator over the elements in this list + * (in proper sequence). + * + * @return a list iterator over the elements in this list + * (in proper sequence) + */ + @Override + public ListIterator listIterator() { + return null; + } +} From 21c6acbce8f92b9f5ddf2fdd20a47cb5f13a8bed Mon Sep 17 00:00:00 2001 From: Paul W Date: Wed, 11 Jan 2023 14:50:10 -0800 Subject: [PATCH 02/15] added a few methods ... --- src/edu/greenriver/sdev333/ArrayList.java | 25 ++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/edu/greenriver/sdev333/ArrayList.java b/src/edu/greenriver/sdev333/ArrayList.java index 46fa38b..ea65d03 100644 --- a/src/edu/greenriver/sdev333/ArrayList.java +++ b/src/edu/greenriver/sdev333/ArrayList.java @@ -40,7 +40,7 @@ public int size() { */ @Override public boolean isEmpty() { - return false; + return size == 0; } /** @@ -53,6 +53,7 @@ public boolean isEmpty() { */ @Override public boolean contains(ItemType item) { + // AT HOME return false; } @@ -107,7 +108,8 @@ public void add(ItemType item) { */ @Override public void remove(ItemType item) { - + // IN CLASS + // find element, then shift everything else left } /** @@ -116,7 +118,8 @@ public void remove(ItemType item) { */ @Override public void clear() { - + // data = (ItemType[]) new Object[data.length]; + size = 0; } /** @@ -129,7 +132,9 @@ public void clear() { */ @Override public boolean containsAll(Collection otherCollection) { - return false; + // fail LOUD + throw new UnsupportedOperationException(); + //return false; } /** @@ -178,7 +183,10 @@ public void retainAll(Collection otherCollection) { */ @Override public ItemType get(int index) { - return null; + if (index >= size) { + throw new IndexOutOfBoundsException("index is beyond size"); + } + return data[index]; } /** @@ -194,7 +202,10 @@ public ItemType get(int index) { */ @Override public void set(int index, ItemType item) { - + if (index >= size) { + throw new IndexOutOfBoundsException("index is beyond size"); + } + data[index] = item; } /** @@ -211,7 +222,7 @@ public void set(int index, ItemType item) { */ @Override public void add(int index, ItemType item) { - + // AT HOME - try at home } /** From 2d3d8fcc629963e471cbe4a26606eef6581303bb Mon Sep 17 00:00:00 2001 From: Paul Woods Date: Wed, 11 Jan 2023 19:52:54 -0800 Subject: [PATCH 03/15] added the ArrayList.add(index,item) method, tested --- src/Main.java | 52 ++++++++++++++++++++++- src/edu/greenriver/sdev333/ArrayList.java | 21 ++++++++- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/Main.java b/src/Main.java index f3e42e7..9d586b3 100644 --- a/src/Main.java +++ b/src/Main.java @@ -4,7 +4,7 @@ public class Main { public static void main(String[] args) { System.out.println("Hello world!"); - +/* List friends = new ArrayList<>(); System.out.println("initial size is " + friends.size()); @@ -22,5 +22,55 @@ public static void main(String[] args) { friends.add("Sophia"); System.out.println("size is now " + friends.size()); + */ + System.out.println(); + System.out.println("Create list of integers, adding 10 elements, 1 .. 10"); + List intList = new ArrayList<>(); + + intList.add(1); + intList.add(2); + intList.add(3); + intList.add(4); + intList.add(5); + intList.add(6); + intList.add(7); + intList.add(8); + intList.add(9); + intList.add(10); + + System.out.println("Size: " + intList.size()); + for (int i = 0; i < intList.size(); i++) { + System.out.print(intList.get(i) + " "); + } + System.out.println(); + System.out.println(); + + System.out.println("Added 20 to list"); + intList.add(20); + System.out.println("Size: " + intList.size()); + for (int i = 0; i < intList.size(); i++) { + System.out.print(intList.get(i) + " "); + } + System.out.println(); + System.out.println(); + + + System.out.println("Setting index 8 (#9) to 90"); + intList.set(8, 90); + System.out.println("Size: " + intList.size()); + for (int i = 0; i < intList.size(); i++) { + System.out.print(intList.get(i) + " "); + } + System.out.println(); + System.out.println(); + + System.out.println("Set 40 at index 4"); + intList.add(4,40); + System.out.println("Size: " + intList.size()); + for (int i = 0; i < intList.size(); i++) { + System.out.print(intList.get(i) + " "); + } + System.out.println(); + } } \ No newline at end of file diff --git a/src/edu/greenriver/sdev333/ArrayList.java b/src/edu/greenriver/sdev333/ArrayList.java index ea65d03..37e3b33 100644 --- a/src/edu/greenriver/sdev333/ArrayList.java +++ b/src/edu/greenriver/sdev333/ArrayList.java @@ -53,7 +53,12 @@ public boolean isEmpty() { */ @Override public boolean contains(ItemType item) { - // AT HOME + + for (int i = 0; i < size; i++) { + if (data[i].equals(item)) + return true; + } + return false; } @@ -76,7 +81,7 @@ public Iterator iterator() { */ @Override public void add(ItemType item) { - + System.out.print("add(), size starting: " + size + ", size ending: "); data[size++] = item; // all of the above works until I run out of room when size becomes @@ -96,6 +101,8 @@ public void add(ItemType item) { data = temp; } + System.out.println(size); + } /** @@ -223,6 +230,16 @@ public void set(int index, ItemType item) { @Override public void add(int index, ItemType item) { // AT HOME - try at home + + // Add the last item to the end of list, and shift everything behind it to the right + this.add(data[size-1]); + //System.out.println("add(_,_), data[size-1]: " + data[size-1]); + + for (int i = size-2; i > index; i--) { + data[i] = data[i-1]; + } + + set(index, item); } /** From 29a269c8d9da57e31ea989bba5c6c9425a466998 Mon Sep 17 00:00:00 2001 From: Paul Woods Date: Wed, 11 Jan 2023 19:54:16 -0800 Subject: [PATCH 04/15] commented out debugging code in add(item) --- src/edu/greenriver/sdev333/ArrayList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/edu/greenriver/sdev333/ArrayList.java b/src/edu/greenriver/sdev333/ArrayList.java index 37e3b33..fd15b22 100644 --- a/src/edu/greenriver/sdev333/ArrayList.java +++ b/src/edu/greenriver/sdev333/ArrayList.java @@ -81,7 +81,7 @@ public Iterator iterator() { */ @Override public void add(ItemType item) { - System.out.print("add(), size starting: " + size + ", size ending: "); + //System.out.print("add(), size starting: " + size + ", size ending: "); data[size++] = item; // all of the above works until I run out of room when size becomes From 9a949fb85c2283d133682077b8fe4c3eb2cabca5 Mon Sep 17 00:00:00 2001 From: Paul Woods Date: Wed, 11 Jan 2023 20:05:08 -0800 Subject: [PATCH 05/15] implemented indexOf() and lastIndexOf() methods. --- src/Main.java | 27 ++++++++++++++++++++++- src/edu/greenriver/sdev333/ArrayList.java | 19 +++++++++++----- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/Main.java b/src/Main.java index 9d586b3..b311273 100644 --- a/src/Main.java +++ b/src/Main.java @@ -45,7 +45,7 @@ public static void main(String[] args) { System.out.println(); System.out.println(); - System.out.println("Added 20 to list"); + System.out.println("Adding 20 to list"); intList.add(20); System.out.println("Size: " + intList.size()); for (int i = 0; i < intList.size(); i++) { @@ -71,6 +71,31 @@ public static void main(String[] args) { System.out.print(intList.get(i) + " "); } System.out.println(); + System.out.println(); + + System.out.println("Testing indexOf(item), index of 90 should be 9."); + System.out.println(intList.indexOf(90)); + System.out.println("Testing indexOf(item), index of 3 should be 2."); + System.out.println(intList.indexOf(3)); + System.out.println(); + System.out.println(); + + + System.out.println("Adding 5, then 30, then 35 to list"); + intList.add(5); + intList.add(30); + intList.add(35); + System.out.println("Size: " + intList.size()); + for (int i = 0; i < intList.size(); i++) { + System.out.print(intList.get(i) + " "); + } + System.out.println(); + System.out.println(); + + System.out.println("Finding last index of 5, should be 12"); + System.out.println("Calculated lastIndex of 5: " + intList.lastIndexOf(5)); + System.out.println(); + System.out.println(); } } \ No newline at end of file diff --git a/src/edu/greenriver/sdev333/ArrayList.java b/src/edu/greenriver/sdev333/ArrayList.java index fd15b22..aa7b625 100644 --- a/src/edu/greenriver/sdev333/ArrayList.java +++ b/src/edu/greenriver/sdev333/ArrayList.java @@ -81,7 +81,6 @@ public Iterator iterator() { */ @Override public void add(ItemType item) { - //System.out.print("add(), size starting: " + size + ", size ending: "); data[size++] = item; // all of the above works until I run out of room when size becomes @@ -101,8 +100,6 @@ public void add(ItemType item) { data = temp; } - System.out.println(size); - } /** @@ -267,7 +264,13 @@ public void remove(int index) { */ @Override public int indexOf(ItemType item) { - return 0; + // DID AT HOME + for (int i = 0; i < size; i++) { + if (data[i].equals(item)) + return i; + } + + return -1; } /** @@ -282,7 +285,13 @@ public int indexOf(ItemType item) { */ @Override public int lastIndexOf(ItemType item) { - return 0; + // DID AT HOME + for (int i = size-1; i >= 0; i--) { + if (data[i].equals(item)) + return i; + } + + return -1; } /** From 229a1c164ced9c0c2b19d5750af83ce39fe56a19 Mon Sep 17 00:00:00 2001 From: Paul Woods Date: Wed, 18 Jan 2023 21:56:37 -0800 Subject: [PATCH 06/15] completed and tested remaining methods except hashCode() --- src/Main.java | 202 +++++++++++++--- src/edu/greenriver/sdev333/ArrayList.java | 276 +++++++++++++++++++--- 2 files changed, 418 insertions(+), 60 deletions(-) diff --git a/src/Main.java b/src/Main.java index b311273..1d862b1 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,10 +1,20 @@ import edu.greenriver.sdev333.*; +import java.sql.Array; +import java.util.Iterator; + public class Main { - public static void main(String[] args) { - System.out.println("Hello world!"); + private static void printIntList(List l) { + for(int i: l) { + System.out.print(i + " "); + } + System.out.println(); + } + public static void main(String[] args) { /* + System.out.println("Hello world!"); + List friends = new ArrayList<>(); System.out.println("initial size is " + friends.size()); @@ -22,11 +32,32 @@ public static void main(String[] args) { friends.add("Sophia"); System.out.println("size is now " + friends.size()); - */ +*/ + /* + for (int i = 0; i < friends.size(); i++) { + System.out.print(friends.get(i) + " "); + }*/ + /* + Iterator itr = friends.iterator(); + while(itr.hasNext()) { + String name = itr.next(); + System.out.println(name); + } + */ +/* + // Testing iterator() + for (String s: friends) { + System.out.println(s + " "); + } +*/ + System.out.println(); System.out.println("Create list of integers, adding 10 elements, 1 .. 10"); List intList = new ArrayList<>(); + System.out.println("testing isEmpty on empty list, returns: " + intList.isEmpty()); + + // tests .add() intList.add(1); intList.add(2); intList.add(3); @@ -38,64 +69,175 @@ public static void main(String[] args) { intList.add(9); intList.add(10); - System.out.println("Size: " + intList.size()); - for (int i = 0; i < intList.size(); i++) { - System.out.print(intList.get(i) + " "); - } + System.out.println("testing isEmpty on a list with 10 items, returns: " + intList.isEmpty()); + System.out.println(); + System.out.println("Testing get(0):, should return 1: " + intList.get(0)); System.out.println(); + System.out.println("testing contains(), looking for int value 5"); + System.out.println("result of contains(Integer.valueOf(5)): " + intList.contains(Integer.valueOf(5))); + System.out.println("testing contains(), looking for int value of 90"); + System.out.println("result of contains(Integer.valueOf(90)): " + intList.contains(Integer.valueOf(90))); System.out.println(); + System.out.println("Printing list while testing .iterator() ..."); + // tests .iterator() + printIntList(intList); + System.out.println(); + + // test .add() again System.out.println("Adding 20 to list"); intList.add(20); System.out.println("Size: " + intList.size()); - for (int i = 0; i < intList.size(); i++) { - System.out.print(intList.get(i) + " "); - } - System.out.println(); + printIntList(intList); System.out.println(); - + // test .set(index, value) System.out.println("Setting index 8 (#9) to 90"); intList.set(8, 90); System.out.println("Size: " + intList.size()); - for (int i = 0; i < intList.size(); i++) { - System.out.print(intList.get(i) + " "); - } - System.out.println(); + printIntList(intList); System.out.println(); - System.out.println("Set 40 at index 4"); + // test .add(index, value) + System.out.println("Adding 40 at index 4"); intList.add(4,40); System.out.println("Size: " + intList.size()); - for (int i = 0; i < intList.size(); i++) { - System.out.print(intList.get(i) + " "); - } - System.out.println(); + printIntList(intList); System.out.println(); + // test .indexOf(val) System.out.println("Testing indexOf(item), index of 90 should be 9."); System.out.println(intList.indexOf(90)); + System.out.println(); + + // test .indexOf(val) System.out.println("Testing indexOf(item), index of 3 should be 2."); System.out.println(intList.indexOf(3)); System.out.println(); + + // add 5 again, and reprint list + System.out.println("Adding 5 to end of list for next test"); + intList.add(5); + printIntList(intList); System.out.println(); + // test .lastIndexOf(val) + System.out.println("Finding last index of 5, should be 12"); + System.out.println("Calculated lastIndex of 5: " + intList.lastIndexOf(5)); + System.out.println("Finding last index of 40, should be 4"); + System.out.println("Calculated lastIndex of 40: " + intList.lastIndexOf(40)); + System.out.println(); - System.out.println("Adding 5, then 30, then 35 to list"); + printIntList(intList); + + System.out.println("Testing remove(index), removing index 4 (#40)"); + intList.remove(4); + printIntList(intList); + System.out.println(); + + // test containsAll() + List newList = new ArrayList<>(); + newList.add(1); + newList.add(8); + System.out.println("Testing containsAll() with a sublist of 1 and 8, should return true"); + System.out.println("containsAll() result: " + intList.containsAll(newList)); + newList.add(999); + System.out.println("Testing containsAll() with a sublist of 1, 8, and 999 should return false"); + System.out.println("containsAll() result: " + intList.containsAll(newList)); + printIntList(intList); + System.out.println(); + + // tests removeItem(item) + System.out.println("Testing remove(item), removing #90"); + intList.remove(Integer.valueOf(90)); + // NOTE - Use the Integer.valueOf() static method to remove a value as from ArrayList + + printIntList(intList); + System.out.println(); + + + + // test clear() + System.out.println(); + System.out.println("Testing clear(), printed list"); + intList.clear(); + printIntList(intList); + System.out.println(); + + // testing 2nd constructor w/ initial parameter + intList = new ArrayList<>(20); + intList.add(1); + intList.add(2); + intList.add(3); + intList.add(4); intList.add(5); - intList.add(30); - intList.add(35); - System.out.println("Size: " + intList.size()); - for (int i = 0; i < intList.size(); i++) { - System.out.print(intList.get(i) + " "); - } + intList.add(6); + intList.add(7); + intList.add(8); + intList.add(9); + intList.add(10); + System.out.println("Testing 2nd constructor w/ initial size parameter, should have 1..10 entered."); + printIntList(intList); System.out.println(); + + List tempList = new ArrayList<>(); + tempList.add(50); + tempList.add(51); + tempList.add(52); + tempList.add(53); + tempList.add(54); + tempList.add(55); + System.out.println("Testing addAll(), adding a new collection that contains 50 ... 55 to list"); + intList.addAll(tempList); + printIntList(intList); System.out.println(); - System.out.println("Finding last index of 5, should be 12"); - System.out.println("Calculated lastIndex of 5: " + intList.lastIndexOf(5)); + // testing equals() method + System.out.println("Testing equals() method, original list vs tempList (50..55), should be false"); + System.out.println("Result of intList.equals(tempList): " + intList.equals(tempList)); + System.out.println("Testing equals method, tempList (50..55) vs bList (50..55), should be true"); + List bList = new ArrayList<>(); + bList.add(50); + bList.add(51); + bList.add(52); + bList.add(53); + bList.add(54); + bList.add(55); + System.out.println("Result of tempList.equals(bList): " + tempList.equals(bList)); + System.out.println(); + System.out.println("Original list again:"); + printIntList(intList); System.out.println(); + List cList = new ArrayList<>(); + cList.add(1); + cList.add(5); + cList.add(9); + cList.add(52); + cList.add(55); + + // testing removeAll(collection) + System.out.println("Will be removing cList from our original list, cList is:"); + printIntList(cList); + System.out.println("Testing removeAll(collection), removing cList from intList."); + intList.removeAll(cList); + System.out.println("Resulting list: "); + printIntList(intList); + System.out.println(); + + // testing retainAll() + System.out.println("We are going to test retainAll(), but lets add items back to our original list."); + System.out.println("Original list again:"); + intList.addAll(cList); + printIntList(intList); + System.out.println("cList again is:"); + printIntList(cList); + System.out.println("We are going to retain only the items in cList that are in our original list"); + intList.retainAll(cList); + System.out.println("Resulting original list:"); + printIntList(intList); + + } } \ No newline at end of file diff --git a/src/edu/greenriver/sdev333/ArrayList.java b/src/edu/greenriver/sdev333/ArrayList.java index aa7b625..a57faaf 100644 --- a/src/edu/greenriver/sdev333/ArrayList.java +++ b/src/edu/greenriver/sdev333/ArrayList.java @@ -2,7 +2,18 @@ import java.util.Iterator; import java.util.ListIterator; - +//import java.util.function.Consumer; + +/** + * This class implements the List interface in the Java collections + * package. The individual public methods are tested in the + * corresponding Main class, with comments there regarding each + * method tested. + * + * @author Paul Woods + * + * @param + */ public class ArrayList implements List { // WE NEED FIELDS @@ -20,7 +31,10 @@ public ArrayList() { data = (ItemType[]) new Object[10]; } - + public ArrayList(int initial) { + size = 0; + data = (ItemType[]) new Object[initial]; + } /** @@ -53,13 +67,11 @@ public boolean isEmpty() { */ @Override public boolean contains(ItemType item) { - - for (int i = 0; i < size; i++) { - if (data[i].equals(item)) - return true; + if (item == null) { + throw new NullPointerException(); } - return false; + return (indexOf(item) != -1); } /** @@ -69,7 +81,7 @@ public boolean contains(ItemType item) { */ @Override public Iterator iterator() { - return null; + return new OurCustomIterator(); } /** @@ -85,6 +97,15 @@ public void add(ItemType item) { // all of the above works until I run out of room when size becomes // the same as length, I'm out of room + checkSize(); + + } + + /* + * check for size increase requirement, and double-array size + * if necessary + */ + private void checkSize() { if (size == data.length) { // resize up .... @@ -99,7 +120,6 @@ public void add(ItemType item) { // Step 3 - point 'data' at temp array data = temp; } - } /** @@ -112,8 +132,14 @@ public void add(ItemType item) { */ @Override public void remove(ItemType item) { + if (item == null) { + throw new NullPointerException(); + } // IN CLASS - // find element, then shift everything else left + int i = indexOf(item); + if (i != -1) { + remove(i); + } } /** @@ -136,9 +162,13 @@ public void clear() { */ @Override public boolean containsAll(Collection otherCollection) { - // fail LOUD - throw new UnsupportedOperationException(); - //return false; + + for (ItemType i: otherCollection) { + if (!contains(i)) + return false; + } + + return true; } /** @@ -148,7 +178,11 @@ public boolean containsAll(Collection otherCollection) { */ @Override public void addAll(Collection otherCollection) { - + if (otherCollection != null) { + for (ItemType i: otherCollection) { + this.add(i); + } + } } /** @@ -161,7 +195,9 @@ public void addAll(Collection otherCollection) { */ @Override public void removeAll(Collection otherCollection) { - + for (ItemType i: otherCollection) { + remove(i); + } } /** @@ -174,7 +210,18 @@ public void removeAll(Collection otherCollection) { */ @Override public void retainAll(Collection otherCollection) { + // Create a value-copy of current list + List listCopy = new ArrayList<>(); + for (ItemType i: this) { + listCopy.add(i); + } + // remove items in otherCollection from listCopy + // this leaves us with an inverted view of the list + listCopy.removeAll(otherCollection); + + // now remove listCopy items from originalList + this.removeAll(listCopy); } /** @@ -187,10 +234,12 @@ public void retainAll(Collection otherCollection) { */ @Override public ItemType get(int index) { - if (index >= size) { + if (validIndex(index)) { + return data[index]; + } + else { throw new IndexOutOfBoundsException("index is beyond size"); } - return data[index]; } /** @@ -206,10 +255,11 @@ public ItemType get(int index) { */ @Override public void set(int index, ItemType item) { - if (index >= size) { + if (validIndex(index)) { + data[index] = item; + } else { throw new IndexOutOfBoundsException("index is beyond size"); } - data[index] = item; } /** @@ -226,17 +276,17 @@ public void set(int index, ItemType item) { */ @Override public void add(int index, ItemType item) { - // AT HOME - try at home + if (validIndex(index)) { + // Add the last item to the end of list, and shift everything behind it to the right + this.add(data[size-1]); - // Add the last item to the end of list, and shift everything behind it to the right - this.add(data[size-1]); - //System.out.println("add(_,_), data[size-1]: " + data[size-1]); + for (int i = size-2; i > index; i--) { + data[i] = data[i-1]; + } - for (int i = size-2; i > index; i--) { - data[i] = data[i-1]; + // finally, set the 'added' item to the specified location + set(index, item); } - - set(index, item); } /** @@ -249,7 +299,15 @@ public void add(int index, ItemType item) { */ @Override public void remove(int index) { + if (index < 0 || index >= size) { + throw new IndexOutOfBoundsException(); + } + for (int i = index; i < size - 1; i++) { + data[i] = data[i + 1]; + } + + size--; } /** @@ -285,7 +343,6 @@ public int indexOf(ItemType item) { */ @Override public int lastIndexOf(ItemType item) { - // DID AT HOME for (int i = size-1; i >= 0; i--) { if (data[i].equals(item)) return i; @@ -303,6 +360,165 @@ public int lastIndexOf(ItemType item) { */ @Override public ListIterator listIterator() { - return null; + return new SecondCustomIterator(); + } + + /** + * Per the Oracle javadocs, "... two lists are defined to be equal + * if they contain the same elements in the same order." + * @param obj object to be compared for equality with this collection + * @return + */ + @Override + public boolean equals(Object obj) { + // Must first ensure these two objects are of the same type ... + if (obj != null && obj.getClass() == this.getClass()) { + + // create temporary ArrayList from obj + ArrayList temp = (ArrayList) obj; + + // confirm lists are of equal size, if not, return false + if (this.size() != temp.size()) + return false; + + // cycle through individual items, testing one by one + // return false if one of pair is not equal + for (int i = 0; i < this.size(); i++) { + if (this.get(i) != temp.get(i)) + return false; + } + } + + return true; } -} + + /** + * This method tests a given index value to determine if it + * is valid. Any index out of range, i.e. smaller than 0 + * or larger than size, is invalid and does not point to + * a valid element. + * @param index + * @return + */ + private boolean validIndex(int index) { + return ((index < this.size) && (index >= 0)); + } + + /** + * This method resizes the array, doubling its previous value, to + * make way for new elements. Called as required by various methods. + */ + private void resize() { + // Step 1 - create a temp array 2x size + ItemType[] temp = (ItemType[]) new Object[data.length * 2];; + + // Step 2 - copy arrayElements from data to temp + for (int i = 0; i < size; i++) { + temp[i] = data[i]; + } + + // Step 3 - point 'data' at temp array + data = temp; + } + + private class OurCustomIterator implements Iterator { + + // fields + private int currentPosition; + + public OurCustomIterator() { + currentPosition = 0; + } + + @Override + public boolean hasNext() { + return currentPosition < size(); + } + + @Override + public ItemType next() { + ItemType result = get(currentPosition); + currentPosition++; + return result; + } + + } + + /** + * Implemented methods using primarily same logic as CustomerIterator + * above, though the extra methods were completed using documentation found + * for the JDK at + * https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html#previousIndex-- + */ + private class SecondCustomIterator implements ListIterator { + + // fancier Iterator that lets us go forwards and backwards + private int currentPosition; + private int lastIndexReturned; + + public SecondCustomIterator() { + currentPosition = 0; + } + + @Override + public boolean hasNext() { + return currentPosition < size(); + } + + @Override + public ItemType next() { + ItemType result = get(currentPosition); + lastIndexReturned = currentPosition; + currentPosition++; + return result; + } + + @Override + public boolean hasPrevious() { + return currentPosition > 0; + } + + @Override + public ItemType previous() { + if (currentPosition > 0) { + ItemType result = get(currentPosition - 1); + lastIndexReturned = currentPosition - 1; + return result; + } else { + throw new IndexOutOfBoundsException(); + } + } + + @Override + public int nextIndex() { + if (currentPosition == size() - 1) + return currentPosition; + else + return currentPosition + 1; + } + + @Override + public int previousIndex() { + if (currentPosition == 0) + return -1; + else + return currentPosition - 1; + } + + @Override + public void remove() { + ArrayList.this.remove(lastIndexReturned); + } + + @Override + public void set(ItemType itemType) { + ArrayList.this.set(lastIndexReturned, itemType); + } + + @Override + public void add(ItemType itemType) { + + } + } + +} // end of class ArrayList From 9d12319f051f7deb053b4e492b7ca56196a6d677 Mon Sep 17 00:00:00 2001 From: Paul Woods Date: Wed, 18 Jan 2023 22:03:15 -0800 Subject: [PATCH 07/15] Additional comments --- src/Main.java | 45 ++++------------------- src/edu/greenriver/sdev333/ArrayList.java | 6 +++ 2 files changed, 13 insertions(+), 38 deletions(-) diff --git a/src/Main.java b/src/Main.java index 1d862b1..52bed33 100644 --- a/src/Main.java +++ b/src/Main.java @@ -3,6 +3,13 @@ import java.sql.Array; import java.util.Iterator; +/** + * Main Class used to test functionality of ArrayList implementation. + * Inside the main() method are comments and code regarding the setup + * and testing for each given method. + * + * @author Paul Woods + */ public class Main { private static void printIntList(List l) { @@ -12,44 +19,6 @@ private static void printIntList(List l) { System.out.println(); } public static void main(String[] args) { -/* - System.out.println("Hello world!"); - - List friends = new ArrayList<>(); - - System.out.println("initial size is " + friends.size()); - - friends.add("Jess"); - friends.add("Tina"); - friends.add("Josh"); - friends.add("Susan"); - friends.add("Dee"); - friends.add("Tyler"); - friends.add("Usman"); - friends.add("Rose"); - friends.add("Blanche"); - friends.add("Dorothy"); - friends.add("Sophia"); - - System.out.println("size is now " + friends.size()); -*/ - /* - for (int i = 0; i < friends.size(); i++) { - System.out.print(friends.get(i) + " "); - }*/ - /* - Iterator itr = friends.iterator(); - while(itr.hasNext()) { - String name = itr.next(); - System.out.println(name); - } - */ -/* - // Testing iterator() - for (String s: friends) { - System.out.println(s + " "); - } -*/ System.out.println(); System.out.println("Create list of integers, adding 10 elements, 1 .. 10"); diff --git a/src/edu/greenriver/sdev333/ArrayList.java b/src/edu/greenriver/sdev333/ArrayList.java index a57faaf..3a65918 100644 --- a/src/edu/greenriver/sdev333/ArrayList.java +++ b/src/edu/greenriver/sdev333/ArrayList.java @@ -10,6 +10,12 @@ * corresponding Main class, with comments there regarding each * method tested. * + * Implemented and tested all listed methods except for hashCode(). I read in + * prior class notes from CS145 "If the .equals() method returns true on two objects, + * their hashCode() must also return the same value." I am unsure how I can + * get two 'equal' lists to return the same hashCode if they have equal objects, + * so am going to forgo that method for now. + * * @author Paul Woods * * @param From beeab9c5c5b0c68e8d614b5f416953e8274da0e9 Mon Sep 17 00:00:00 2001 From: Paul Woods Date: Wed, 18 Jan 2023 22:06:48 -0800 Subject: [PATCH 08/15] Additional comments ... part 2, removed unused imports --- src/Main.java | 7 ++----- src/edu/greenriver/sdev333/ArrayList.java | 1 - 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Main.java b/src/Main.java index 52bed33..a528d5c 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,8 +1,5 @@ import edu.greenriver.sdev333.*; -import java.sql.Array; -import java.util.Iterator; - /** * Main Class used to test functionality of ArrayList implementation. * Inside the main() method are comments and code regarding the setup @@ -99,6 +96,7 @@ public static void main(String[] args) { printIntList(intList); + // testing remove(index) System.out.println("Testing remove(index), removing index 4 (#40)"); intList.remove(4); printIntList(intList); @@ -124,8 +122,6 @@ public static void main(String[] args) { printIntList(intList); System.out.println(); - - // test clear() System.out.println(); System.out.println("Testing clear(), printed list"); @@ -149,6 +145,7 @@ public static void main(String[] args) { printIntList(intList); System.out.println(); + // testing addAll(collection) List tempList = new ArrayList<>(); tempList.add(50); tempList.add(51); diff --git a/src/edu/greenriver/sdev333/ArrayList.java b/src/edu/greenriver/sdev333/ArrayList.java index 3a65918..d31c5cb 100644 --- a/src/edu/greenriver/sdev333/ArrayList.java +++ b/src/edu/greenriver/sdev333/ArrayList.java @@ -2,7 +2,6 @@ import java.util.Iterator; import java.util.ListIterator; -//import java.util.function.Consumer; /** * This class implements the List interface in the Java collections From 48d08c6b0eedb6b15ca04a32061b9711761c4b24 Mon Sep 17 00:00:00 2001 From: Paul Woods Date: Mon, 23 Jan 2023 20:47:19 -0800 Subject: [PATCH 09/15] Added DoublyLinkedList and SinglyLinkedList, the former is testing correct so far. --- src/Main.java | 11 +- .../greenriver/sdev333/DoublyLinkedList.java | 422 ++++++++++++++++++ .../greenriver/sdev333/SinglyLinkedList.java | 255 +++++++++++ 3 files changed, 687 insertions(+), 1 deletion(-) create mode 100644 src/edu/greenriver/sdev333/DoublyLinkedList.java create mode 100644 src/edu/greenriver/sdev333/SinglyLinkedList.java diff --git a/src/Main.java b/src/Main.java index a528d5c..85261b2 100644 --- a/src/Main.java +++ b/src/Main.java @@ -19,7 +19,8 @@ public static void main(String[] args) { System.out.println(); System.out.println("Create list of integers, adding 10 elements, 1 .. 10"); - List intList = new ArrayList<>(); + //List intList = new ArrayList<>(); + List intList = new DoublyLinkedList<>(); System.out.println("testing isEmpty on empty list, returns: " + intList.isEmpty()); @@ -35,6 +36,14 @@ public static void main(String[] args) { intList.add(9); intList.add(10); + // NEW FOR DOUBLYLINKEDARRAYLIST +// System.out.println("Printing List organically w/o iterator"); +// for (int i = 0; i < intList.size(); i++) { +// System.out.print(intList.get(i) + " "); +// } +// System.out.println(); + // END NEW TEST + System.out.println("testing isEmpty on a list with 10 items, returns: " + intList.isEmpty()); System.out.println(); System.out.println("Testing get(0):, should return 1: " + intList.get(0)); diff --git a/src/edu/greenriver/sdev333/DoublyLinkedList.java b/src/edu/greenriver/sdev333/DoublyLinkedList.java new file mode 100644 index 0000000..332e03c --- /dev/null +++ b/src/edu/greenriver/sdev333/DoublyLinkedList.java @@ -0,0 +1,422 @@ +package edu.greenriver.sdev333; + +import java.util.Iterator; +import java.util.ListIterator; + +public class DoublyLinkedList implements List{ + + private Node head; + private int size; + + // helper/inner class + private class Node { + ItemType data; + Node next; + Node previous; + } + + // TODO - Implement this Iterator, I don't really understand how they work + private class OurCustomIterator implements Iterator { + + private Node iHead; + + public OurCustomIterator() { + iHead = DoublyLinkedList.this.head; + } + @Override + public boolean hasNext() { + if ((iHead != null ) && iHead.next != null) + return true; + + return false; + + //return !(iHead.next == null); + } + + @Override + public ItemType next() { + iHead = iHead.next; + ItemType result = (ItemType) iHead.data; + return result; + } + } + + /* + * Return a pointer to the last element in the linked-list + */ + private Node getLastElement() { + if (size == 0) { + return null; + } else { + Node n = head; + while (n.next != null) { + n = n.next; + } + return n; + } + } + + /* + * Return element at index n + */ + private Node getElementN(int index) { + + //System.out.print("Retrieving element " + index + ", "); + + if ((index >= size) || (index < 0)) + throw new IndexOutOfBoundsException(); + + Node n = head; + int i = -1; + + while (n.next != null) { + i++; + n = n.next; + if (i == index) { + //System.out.println("data, " + n.data); + return n; + } + } + + // we shouldn't be here ... + throw new NullPointerException(); + } + + public DoublyLinkedList() { + // A new list contains no elemenets, so its head is null + head = null; + size = 0; + } + + /** + * Returns the number of items in this collection. + * + * @return the number of items in this collection + */ + @Override + public int size() { + return size; + } + + /** + * Returns true if this collection contains no items. + * + * @return true if this collection contains no items + */ + @Override + public boolean isEmpty() { + return size == 0; + } + + /** + * Returns true if this collection contains the specified item. + * + * @param item items whose presence in this collection is to be tested + * @return true if this collection contains the specified item + * @throws NullPointerException if the specified item is null + * and this collection does not permit null items + */ + @Override + public boolean contains(ItemType item) { + + if (size == 0) + return false; + + return indexOf(item) != -1; + } + + /** + * Returns an iterator over the elements in this collection. + * + * @return an Iterator over the elements in this collection + */ + @Override + public Iterator iterator() { + return new OurCustomIterator<>(); + } + + /** + * Adds the specified item to the collection. + * + * @param item item to be added to the collection + * @throws NullPointerException if the specified item is null + * and this collection does not permit null items + */ + @Override + public void add(ItemType item) { + + if (head == null) { + head = new Node(); + head.next = new Node(); + head.next.data = item; + } else { + Node currentLast = getLastElement(); + + currentLast.next = new Node(); + currentLast.next.data = item; + currentLast.next.previous = currentLast; + } + + ++size; + } + + /** + * Removes a single instance of the specified item from this collection, + * if it is present. + * + * @param item item to be removed from this collection, if present + * @throws NullPointerException if the specified item is null + * and this collection does not permit null items + */ + @Override + public void remove(ItemType item) { + Node n = head; + while (n.next != null) { + n = n.next; + if (n.data.equals(item)) { + n.next.previous = n.previous; // assign 'previous' for following node to prior node + n.previous.next = n.next; // assign 'next' for prior node to n.next + --size; + return; + } + } + } + + /** + * Removes all items from this collection. + * The collection will be empty after this method returns. + */ + @Override + public void clear() { + head = null; + size = 0; + } + + /** + * Returns true if this collection contains all the items + * in the specified other collection. + * + * @param otherCollection collection to be checked for containment in this collection + * @return true if this collection contains all the items + * in the specified other collection + */ + @Override + public boolean containsAll(Collection otherCollection) { + // Cycle through otherCollection, and when find an element from that + // collection here, remove it. If at some point we do not find one of those + // elements, return false. If we make it through the list, return true + for (ItemType i: otherCollection) { + if (!this.contains(i)) + return false; + } + + return true; + } + + /** + * Adds all the items in this specified other collection to this collection. + * + * @param otherCollection collection containing items to be added to this collection + */ + @Override + public void addAll(Collection otherCollection) { + if (otherCollection != null) { + for (ItemType i: otherCollection) { + this.add(i); + } + } + } + + /** + * Removes all of this collection's items that are also contained in the + * specified other collection. After this call returns, this collection will + * contain no elements in common with the specified other collection. + * + * @param otherCollection collection containing elements to be removed + * from this collection + */ + @Override + public void removeAll(Collection otherCollection) { + if (otherCollection != null) { + for (ItemType i: otherCollection) { + this.remove(i); + } + } + } + + /** + * Retains only the items in this collection that are contained in the + * specified other collection. In other words, removes from this collection + * all of its items that are not contained in the specified other collection + * + * @param otherCollection collection containing elements to be retained in + * this collection + */ + @Override + public void retainAll(Collection otherCollection) { + // Create a value-copy of current list + List listCopy = new ArrayList<>(); + for (ItemType i: this) { + listCopy.add(i); + } + + // remove items in otherCollection from listCopy + // this leaves us with an inverted view of the list + listCopy.removeAll(otherCollection); + + // now remove listCopy items from originalList + this.removeAll(listCopy); + } + + /** + * Returns the item at the specified position in this list + * + * @param index index of the item to return + * @return the item at the specified position in this list + * @throws IndexOutOfBoundsException if this index is out of range + * (index < 0 || index >= size()) + */ + @Override + public ItemType get(int index) { + return getElementN(index).data; + } + + /** + * Replaces the item at the specified position in this list + * with the specified item + * + * @param index index of the item to replace + * @param item item to be stored at the specified position + * @throws NullPointerException if the specified item is null + * and this list does not permit null elements + * @throws IndexOutOfBoundsException if the index is out of range + * (index < 0 || index >= size()) + */ + @Override + public void set(int index, ItemType item) { + if (item == null) + throw new NullPointerException(); + + Node i = getElementN(index); + i.data = item; + } + + /** + * Inserts the specified item at the specified position in this list. + * Shifts the item currently at that position (if any) and any subsequent + * items to the right. + * + * @param index index at which the specified item is to be inserted + * @param item item to be inserted + * @throws NullPointerException if the specified item is null + * and this list does not permit null elements + * @throws IndexOutOfBoundsException if the index is out of range + * (index < 0 || index >= size()) + */ + @Override + public void add(int index, ItemType item) { + if (item == null) + throw new NullPointerException(); + + Node i = getElementN(index); + Node n = new Node(); + n.data = item; + n.previous = i.previous; // previous value for new node + n.next = i; // next value for new node + i.previous.next = n; // next value for old prior node + i.previous = n; // previous value for old node + ++size; + } + + /** + * Removes the element at the specified position in this list. + * Shifts any subsequent items to the left. + * + * @param index the index of the item to be removed + * @throws IndexOutOfBoundsException if the index is out of range + * (index < 0 || index >= size()) + */ + @Override + public void remove(int index) { + Node i = getElementN(index); + i.previous.next = i.next; + i.next.previous = i.previous; + --size; + } + + /** + * Returns the index of the first occurrence of the specified item + * in this list, or -1 if this list does not contain the item. + * + * @param item the item to search for + * @return the index of the first occurrence of the specified item + * in this list, or -1 if this list does not contain the item + * @throws NullPointerException if the specified item is null and this + * list does not permit null items + */ + @Override + public int indexOf(ItemType item) { + if (item == null) + throw new NullPointerException(); + + Node n = head; + int i = -1; + + while (n.next != null) { + i++; + n = n.next; + if (n.data.equals(item)) + return i; + } + + return -1; + } + + /** + * Returns the index of the last occurrence of the specified item + * in this list, or -1 if this list does not contain the item. + * + * @param item the item to search for + * @return the index of the first occurrence of the specified item + * in this list, or -1 if this list does not contain the item + * @throws NullPointerException if the specified item is null and this + * list does not permit null items + */ + @Override + public int lastIndexOf(ItemType item) { + + if (item == null) + throw new NullPointerException(); + + Node n = getLastElement(); + int index = size - 1; + + while (true) { + + if (n.data.equals(item)) + return index; + + if (n.previous != null) { + n = n.previous; + //System.out.println("cycling through last-index, looking for " + item + ", have " + n.data); + --index; + } else { + break; + } + } + + return -1; + } + + /** + * Returns a list iterator over the elements in this list + * (in proper sequence). + * + * @return a list iterator over the elements in this list + * (in proper sequence) + */ + @Override + public ListIterator listIterator() { + return null; + } +} diff --git a/src/edu/greenriver/sdev333/SinglyLinkedList.java b/src/edu/greenriver/sdev333/SinglyLinkedList.java new file mode 100644 index 0000000..d729f24 --- /dev/null +++ b/src/edu/greenriver/sdev333/SinglyLinkedList.java @@ -0,0 +1,255 @@ +package edu.greenriver.sdev333; + +import java.util.Iterator; +import java.util.ListIterator; + +public class SinglyLinkedList implements List { + + // FIELDS - what does a linked list actually have in it?? + private Node head; + private int size; + + // helper/inner class + private class Node { + ItemType data; + Node next; + } + + /** + * Constructor + */ + public SinglyLinkedList() { + // an empty list has no nodes, + // which means it has no head + head = null; + size = 0; + } + + /** + * Returns the number of items in this collection. + * + * @return the number of items in this collection + */ + @Override + public int size() { + return size; + } + + /** + * Returns true if this collection contains no items. + * + * @return true if this collection contains no items + */ + @Override + public boolean isEmpty() { + return size == 0; + } + + /** + * Returns true if this collection contains the specified item. + * + * @param item items whose presence in this collection is to be tested + * @return true if this collection contains the specified item + * @throws NullPointerException if the specified item is null + * and this collection does not permit null items + */ + @Override + public boolean contains(ItemType item) { + return false; + } + + /** + * Returns an iterator over the elements in this collection. + * + * @return an Iterator over the elements in this collection + */ + @Override + public Iterator iterator() { + return null; + } + + /** + * Adds the specified item to the collection. + * + * @param item item to be added to the collection + * @throws NullPointerException if the specified item is null + * and this collection does not permit null items + */ + @Override + public void add(ItemType item) { + + } + + /** + * Removes a single instance of the specified item from this collection, + * if it is present. + * + * @param item item to be removed from this collection, if present + * @throws NullPointerException if the specified item is null + * and this collection does not permit null items + */ + @Override + public void remove(ItemType item) { + + } + + /** + * Removes all items from this collection. + * The collection will be empty after this method returns. + */ + @Override + public void clear() { + head = null; + size = 0; + } + + /** + * Returns true if this collection contains all the items + * in the specified other collection. + * + * @param otherCollection collection to be checked for containment in this collection + * @return true if this collection contains all the items + * in the specified other collection + */ + @Override + public boolean containsAll(Collection otherCollection) { + return false; + } + + /** + * Adds all the items in this specified other collection to this collection. + * + * @param otherCollection collection containing items to be added to this collection + */ + @Override + public void addAll(Collection otherCollection) { + + } + + /** + * Removes all of this collection's items that are also contained in the + * specified other collection. After this call returns, this collection will + * contain no elements in common with the specified other collection. + * + * @param otherCollection collection containing elements to be removed + * from this collection + */ + @Override + public void removeAll(Collection otherCollection) { + + } + + /** + * Retains only the items in this collection that are contained in the + * specified other collection. In other words, removes from this collection + * all of its items that are not contained in the specified other collection + * + * @param otherCollection collection containing elements to be retained in + * this collection + */ + @Override + public void retainAll(Collection otherCollection) { + + } + + /** + * Returns the item at the specified position in this list + * + * @param index index of the item to return + * @return the item at the specified position in this list + * @throws IndexOutOfBoundsException if this index is out of range + * (index < 0 || index >= size()) + */ + @Override + public ItemType get(int index) { + return null; + } + + /** + * Replaces the item at the specified position in this list + * with the specified item + * + * @param index index of the item to replace + * @param item item to be stored at the specified position + * @throws NullPointerException if the specified item is null + * and this list does not permit null elements + * @throws IndexOutOfBoundsException if the index is out of range + * (index < 0 || index >= size()) + */ + @Override + public void set(int index, ItemType item) { + + } + + /** + * Inserts the specified item at the specified position in this list. + * Shifts the item currently at that position (if any) and any subsequent + * items to the right. + * + * @param index index at which the specified item is to be inserted + * @param item item to be inserted + * @throws NullPointerException if the specified item is null + * and this list does not permit null elements + * @throws IndexOutOfBoundsException if the index is out of range + * (index < 0 || index >= size()) + */ + @Override + public void add(int index, ItemType item) { + + } + + /** + * Removes the element at the specified position in this list. + * Shifts any subsequent items to the left. + * + * @param index the index of the item to be removed + * @throws IndexOutOfBoundsException if the index is out of range + * (index < 0 || index >= size()) + */ + @Override + public void remove(int index) { + + } + + /** + * Returns the index of the first occurrence of the specified item + * in this list, or -1 if this list does not contain the item. + * + * @param item the item to search for + * @return the index of the first occurrence of the specified item + * in this list, or -1 if this list does not contain the item + * @throws NullPointerException if the specified item is null and this + * list does not permit null items + */ + @Override + public int indexOf(ItemType item) { + return 0; + } + + /** + * Returns the index of the last occurrence of the specified item + * in this list, or -1 if this list does not contain the item. + * + * @param item the item to search for + * @return the index of the first occurrence of the specified item + * in this list, or -1 if this list does not contain the item + * @throws NullPointerException if the specified item is null and this + * list does not permit null items + */ + @Override + public int lastIndexOf(ItemType item) { + return 0; + } + + /** + * Returns a list iterator over the elements in this list + * (in proper sequence). + * + * @return a list iterator over the elements in this list + * (in proper sequence) + */ + @Override + public ListIterator listIterator() { + return null; + } +} From 29660211b495b3f21eb6bbd557164230f2e04267 Mon Sep 17 00:00:00 2001 From: Paul W Date: Wed, 25 Jan 2023 14:20:18 -0800 Subject: [PATCH 10/15] Added some code in class to SinglyLinkedList --- .idea/misc.xml | 2 +- .../greenriver/sdev333/SinglyLinkedList.java | 69 ++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 07115cd..05b1176 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/edu/greenriver/sdev333/SinglyLinkedList.java b/src/edu/greenriver/sdev333/SinglyLinkedList.java index d729f24..93b1e3c 100644 --- a/src/edu/greenriver/sdev333/SinglyLinkedList.java +++ b/src/edu/greenriver/sdev333/SinglyLinkedList.java @@ -7,6 +7,7 @@ public class SinglyLinkedList implements List { // FIELDS - what does a linked list actually have in it?? private Node head; + private Node tail; private int size; // helper/inner class @@ -25,6 +26,50 @@ public SinglyLinkedList() { size = 0; } + + + /* + * Return a pointer to the last element in the linked-list + */ + private SinglyLinkedList.Node getLastElement() { + if (size == 0) { + return null; + } else { + SinglyLinkedList.Node n = head; + while (n.next != null) { + n = n.next; + } + return n; + } + } + + + /* + * Return element at index n + */ + private SinglyLinkedList.Node getElementN(int index) { + + //System.out.print("Retrieving element " + index + ", "); + + if ((index >= size) || (index < 0)) + throw new IndexOutOfBoundsException(); + + SinglyLinkedList.Node n = head; + int i = -1; + + while (n.next != null) { + i++; + n = n.next; + if (i == index) { + //System.out.println("data, " + n.data); + return n; + } + } + + // we shouldn't be here ... + throw new NullPointerException(); + } + /** * Returns the number of items in this collection. * @@ -78,6 +123,18 @@ public Iterator iterator() { @Override public void add(ItemType item) { + if (head == null) { + head = new SinglyLinkedList.Node(); + head.next = new SinglyLinkedList.Node(); + head.next.data = item; + } else { + SinglyLinkedList.Node currentLast = getLastElement(); + + currentLast.next = new SinglyLinkedList.Node(); + currentLast.next.data = item; + } + + ++size; } /** @@ -195,7 +252,17 @@ public void set(int index, ItemType item) { */ @Override public void add(int index, ItemType item) { - + if (item == null) + throw new NullPointerException(); +// +// DoublyLinkedList.Node i = getElementN(index); +// DoublyLinkedList.Node n = new DoublyLinkedList.Node(); +// n.data = item; +// n.previous = i.previous; // previous value for new node +// n.next = i; // next value for new node +// i.previous.next = n; // next value for old prior node +// i.previous = n; // previous value for old node +// ++size; } /** From 9f0236725d9e7577e7560806f193beac823490d9 Mon Sep 17 00:00:00 2001 From: Paul Woods Date: Mon, 30 Jan 2023 19:57:44 -0800 Subject: [PATCH 11/15] Added Iterator and ListIterator, bug fixes, and lots of testing in Main --- .idea/misc.xml | 2 +- src/Main.java | 106 ++++++++++- .../greenriver/sdev333/DoublyLinkedList.java | 178 ++++++++++++++++-- 3 files changed, 260 insertions(+), 26 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 05b1176..07115cd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/Main.java b/src/Main.java index 85261b2..57a9302 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,5 +1,7 @@ import edu.greenriver.sdev333.*; +import java.util.ListIterator; + /** * Main Class used to test functionality of ArrayList implementation. * Inside the main() method are comments and code regarding the setup @@ -35,6 +37,49 @@ public static void main(String[] args) { intList.add(8); intList.add(9); intList.add(10); + printIntList(intList); +/* + System.out.println("removing index 5 (#6)"); + intList.remove(5); + printIntList(intList); + + System.out.println("removing index 0 (#1)"); + intList.remove(0); // remove index + printIntList(intList); + + System.out.println("removing item 2"); + intList.remove(Integer.valueOf(2)); // remove item - problem w/ iterator after this point + printIntList(intList); + + System.out.println("removing item 7"); + intList.remove(Integer.valueOf(7)); + printIntList(intList); + + System.out.println("Clearing list, then adding numbers 21..25"); + intList.clear(); + + intList.add(21); + intList.add(22); + intList.add(23); + intList.add(24); + intList.add(25); + printIntList(intList); + + // BEGIN TEST ITERATOR + System.out.println("Testing ListIterator forward"); + ListIterator myItr = intList.listIterator(); + while(myItr.hasNext()) { + System.out.print(myItr.next() + " "); + } + System.out.println(); + + System.out.println("Testing in reverse"); + while(myItr.hasPrevious()) { + System.out.print(myItr.previous() + " "); + } + System.out.println(); + // END TEST ITERATOR + */ // NEW FOR DOUBLYLINKEDARRAYLIST // System.out.println("Printing List organically w/o iterator"); @@ -112,7 +157,7 @@ public static void main(String[] args) { System.out.println(); // test containsAll() - List newList = new ArrayList<>(); + List newList = new DoublyLinkedList<>(); newList.add(1); newList.add(8); System.out.println("Testing containsAll() with a sublist of 1 and 8, should return true"); @@ -139,7 +184,7 @@ public static void main(String[] args) { System.out.println(); // testing 2nd constructor w/ initial parameter - intList = new ArrayList<>(20); + intList = new DoublyLinkedList<>(); intList.add(1); intList.add(2); intList.add(3); @@ -151,11 +196,12 @@ public static void main(String[] args) { intList.add(9); intList.add(10); System.out.println("Testing 2nd constructor w/ initial size parameter, should have 1..10 entered."); + System.out.println("Note, no 2nd constructor for DoublyLinkedList, using original ... "); printIntList(intList); System.out.println(); // testing addAll(collection) - List tempList = new ArrayList<>(); + List tempList = new DoublyLinkedList<>(); tempList.add(50); tempList.add(51); tempList.add(52); @@ -171,7 +217,7 @@ public static void main(String[] args) { System.out.println("Testing equals() method, original list vs tempList (50..55), should be false"); System.out.println("Result of intList.equals(tempList): " + intList.equals(tempList)); System.out.println("Testing equals method, tempList (50..55) vs bList (50..55), should be true"); - List bList = new ArrayList<>(); + List bList = new DoublyLinkedList<>(); bList.add(50); bList.add(51); bList.add(52); @@ -183,14 +229,34 @@ public static void main(String[] args) { System.out.println(); System.out.println("Original list again:"); printIntList(intList); + + + // BEGIN TEST ITERATOR + System.out.println("Testing ListIterator forward"); + ListIterator myItr = intList.listIterator(); + while(myItr.hasNext()) { + System.out.print(myItr.next() + " "); + } System.out.println(); - List cList = new ArrayList<>(); + System.out.println("Testing in reverse"); + while(myItr.hasPrevious()) { + System.out.print(myItr.previous() + " "); + } + System.out.println(); + // END TEST ITERATOR + + + + System.out.println(); + + List cList = new DoublyLinkedList<>(); cList.add(1); cList.add(5); cList.add(9); cList.add(52); cList.add(55); + cList.add(72); // testing removeAll(collection) System.out.println("Will be removing cList from our original list, cList is:"); @@ -205,14 +271,42 @@ public static void main(String[] args) { System.out.println("We are going to test retainAll(), but lets add items back to our original list."); System.out.println("Original list again:"); intList.addAll(cList); + + cList.add(99); printIntList(intList); - System.out.println("cList again is:"); + System.out.println("cList again is (added 99 to this list):"); printIntList(cList); System.out.println("We are going to retain only the items in cList that are in our original list"); intList.retainAll(cList); System.out.println("Resulting original list:"); printIntList(intList); + System.out.println("Adding 1..10 to original list again"); + intList.add(1); + intList.add(2); + intList.add(3); + intList.add(4); + intList.add(5); + intList.add(6); + intList.add(7); + intList.add(8); + intList.add(9); + intList.add(10); + printIntList(intList); + + System.out.println("Testing ListIterator forward"); + //ListIterator myItr = intList.listIterator(); + myItr = intList.listIterator(); + while(myItr.hasNext()) { + System.out.print(myItr.next() + " "); + } + System.out.println(); + + System.out.println("Testing in reverse"); + while(myItr.hasPrevious()) { + System.out.print(myItr.previous() + " "); + } + System.out.println(); } } \ No newline at end of file diff --git a/src/edu/greenriver/sdev333/DoublyLinkedList.java b/src/edu/greenriver/sdev333/DoublyLinkedList.java index 332e03c..f71331a 100644 --- a/src/edu/greenriver/sdev333/DoublyLinkedList.java +++ b/src/edu/greenriver/sdev333/DoublyLinkedList.java @@ -15,30 +15,147 @@ private class Node { Node previous; } - // TODO - Implement this Iterator, I don't really understand how they work + /* + * Test w/ for-each statemenet + */ private class OurCustomIterator implements Iterator { private Node iHead; public OurCustomIterator() { - iHead = DoublyLinkedList.this.head; + //iHead = DoublyLinkedList.this.head; + iHead = head; } @Override public boolean hasNext() { - if ((iHead != null ) && iHead.next != null) + // Ken tested for if (currentPostition != null) ... but he had reversed the two lines in next() as well + //return iHead.next != null; + if ((iHead != null) && iHead.next != null) return true; - return false; + } - //return !(iHead.next == null); + /* + * Ken had iHead.next and result = lines reversed + */ + @Override + public ItemType next() { + iHead = iHead.next; + ItemType result = (ItemType) iHead.data; + return result; + } + } + + // geeksforgeeks.org/difference-between-an-iterator-and-listiterator-in-java/ + private class OurListIterator implements ListIterator { + + private Node iHead; + private Node priorNode; + + public OurListIterator() { + iHead = head; + } + @Override + public boolean hasNext() { + return iHead.next != null; } @Override public ItemType next() { iHead = iHead.next; ItemType result = (ItemType) iHead.data; + priorNode = iHead; + return result; + } + + @Override + public boolean hasPrevious() { + //return iHead.previous != null; + //return iHead.previous != null; + return iHead != null; + } + + @Override + public ItemType previous() { + //iHead = iHead.previous; + //ItemType result = (ItemType) iHead.data; + ItemType result = (ItemType) iHead.data; + //if (iHead.previous != null) + iHead = iHead.previous; + priorNode = iHead; return result; } + + @Override + public int nextIndex() { + if (iHead.next == null) + return size(); + + ItemType next = next(); + Node node = head; + int i = 0; + + while (node.next != null) { + node = node.next; + i++; + if (node.next.data.equals(next)) { + return i; + } + } + + return 0; + } + + @Override + public int previousIndex() { + if (iHead.previous == null) + return -1; + + ItemType prev = (ItemType) iHead.previous.data; + Node node = head; + int i = -1; + + while (node.next != null) { + node = node.next; // will be head node w/ index 0 to start + i++; + if (node.data.equals(prev)) { + return i; + } + } + + return -1; + } + + @Override + public void remove() { + // both prior and next nodes ARE NOT null + if (priorNode.previous != null && priorNode.next != null) { + priorNode.previous.next = priorNode.next; // prior nodes' next value = next node + priorNode.next.previous = priorNode.previous; + } + // both prior and next nodes ARE null (single item in list) + else if (priorNode.previous == null && priorNode.next == null) { + iHead.next = null; + } + // prior only IS NULL (1st item in list) + else if (priorNode.previous == null) { + iHead = priorNode.next; + } + // next only IS NULL (last item in list) + else if (priorNode.next == null) { + priorNode.next = null; + } + } + + @Override + public void set(ItemType itemType) { + + } + + @Override + public void add(ItemType itemType) { + + } } /* @@ -145,7 +262,7 @@ public Iterator iterator() { @Override public void add(ItemType item) { - if (head == null) { + if (head == null) { // Add new 1st item, item.previous = null head = new Node(); head.next = new Node(); head.next.data = item; @@ -170,16 +287,30 @@ public void add(ItemType item) { */ @Override public void remove(ItemType item) { + if (item == null) + throw new NullPointerException(); + Node n = head; - while (n.next != null) { - n = n.next; - if (n.data.equals(item)) { - n.next.previous = n.previous; // assign 'previous' for following node to prior node - n.previous.next = n.next; // assign 'next' for prior node to n.next - --size; - return; + + // 1st Node is treated differently as it has no valid previous + if (n.next.data.equals(item)) { + n.next = n.next.next; + n.next.previous = null; + --size; + } + else { + while (n.next != null) { + n = n.next; + if (n.data.equals(item)) { + if (n.next != null) + n.next.previous = n.previous; // assign 'previous' for following node to prior node + n.previous.next = n.next; // assign 'next' for prior node to n.next + --size; + return; + } } } + } /** @@ -318,13 +449,15 @@ public void add(int index, ItemType item) { if (item == null) throw new NullPointerException(); - Node i = getElementN(index); - Node n = new Node(); + Node i = getElementN(index); // current element at index + Node n = new Node(); // new node to be inserted n.data = item; - n.previous = i.previous; // previous value for new node + if (index != 0) + n.previous = i.previous; // previous value for new node n.next = i; // next value for new node i.previous.next = n; // next value for old prior node i.previous = n; // previous value for old node + ++size; } @@ -339,8 +472,15 @@ public void add(int index, ItemType item) { @Override public void remove(int index) { Node i = getElementN(index); - i.previous.next = i.next; - i.next.previous = i.previous; + + if (index == 0) { + head.next = i.next; + i.next.previous = null; + } else { + i.previous.next = i.next; + i.next.previous = i.previous; + } + --size; } @@ -417,6 +557,6 @@ public int lastIndexOf(ItemType item) { */ @Override public ListIterator listIterator() { - return null; + return new OurListIterator<>(); } } From c59a79e2ebe22c5249751fd097cbb15e701424a2 Mon Sep 17 00:00:00 2001 From: Paul Woods Date: Mon, 30 Jan 2023 20:01:23 -0800 Subject: [PATCH 12/15] Added comment to DoublyLinkedList --- src/edu/greenriver/sdev333/DoublyLinkedList.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/edu/greenriver/sdev333/DoublyLinkedList.java b/src/edu/greenriver/sdev333/DoublyLinkedList.java index f71331a..c3c06fc 100644 --- a/src/edu/greenriver/sdev333/DoublyLinkedList.java +++ b/src/edu/greenriver/sdev333/DoublyLinkedList.java @@ -3,6 +3,14 @@ import java.util.Iterator; import java.util.ListIterator; +/** + * This class implements the List interface. Testing is done in the + * Main class, and there were bugs found, esp wrt to the ListIterator + * class. I had to cycle through the Main tests comment them out to + * determine what was interfering with my list of Nodes (was remove(item)). + * + * @author Paul Woods + */ public class DoublyLinkedList implements List{ private Node head; From c33db5b8c05147f79820241efebfb85c2b674170 Mon Sep 17 00:00:00 2001 From: Paul Woods Date: Mon, 30 Jan 2023 20:03:36 -0800 Subject: [PATCH 13/15] Added additional comments to DoublyLinkedList and Main.java --- src/Main.java | 10 ++++++++++ src/edu/greenriver/sdev333/DoublyLinkedList.java | 4 +--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Main.java b/src/Main.java index 57a9302..2e8c3cc 100644 --- a/src/Main.java +++ b/src/Main.java @@ -11,12 +11,22 @@ */ public class Main { + /* + * private method to print our list, utilizes the Iterator + * via a for-each loop to do so. + */ private static void printIntList(List l) { for(int i: l) { System.out.print(i + " "); } System.out.println(); } + + /** + * Our main method where we have our testing for our List + * classes. + * @param args + */ public static void main(String[] args) { System.out.println(); diff --git a/src/edu/greenriver/sdev333/DoublyLinkedList.java b/src/edu/greenriver/sdev333/DoublyLinkedList.java index c3c06fc..6573390 100644 --- a/src/edu/greenriver/sdev333/DoublyLinkedList.java +++ b/src/edu/greenriver/sdev333/DoublyLinkedList.java @@ -182,12 +182,10 @@ private Node getLastElement() { } /* - * Return element at index n + * Return element at index n (not the data in that element) */ private Node getElementN(int index) { - //System.out.print("Retrieving element " + index + ", "); - if ((index >= size) || (index < 0)) throw new IndexOutOfBoundsException(); From a50bdc4787f79d01792c9056af323a46cd962e14 Mon Sep 17 00:00:00 2001 From: Paul Woods Date: Fri, 3 Feb 2023 13:28:53 -0800 Subject: [PATCH 14/15] corrected equals() method in DoublyLinkedList, and created a validateIndex(index) method. --- .idea/misc.xml | 2 +- .../greenriver/sdev333/DoublyLinkedList.java | 52 +++++++++++++++++-- .../greenriver/sdev333/SinglyLinkedList.java | 10 ++++ 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 07115cd..03f397c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/edu/greenriver/sdev333/DoublyLinkedList.java b/src/edu/greenriver/sdev333/DoublyLinkedList.java index 6573390..f97c1c2 100644 --- a/src/edu/greenriver/sdev333/DoublyLinkedList.java +++ b/src/edu/greenriver/sdev333/DoublyLinkedList.java @@ -5,9 +5,10 @@ /** * This class implements the List interface. Testing is done in the - * Main class, and there were bugs found, esp wrt to the ListIterator - * class. I had to cycle through the Main tests comment them out to - * determine what was interfering with my list of Nodes (was remove(item)). + * Main class, and there were intial bugs found and then corrected, + * esp wrt to the ListIterator class. I had to cycle through the + * Main tests comment them out to determine what was interfering + * with my list of Nodes (was remove(item)). * * @author Paul Woods */ @@ -181,13 +182,21 @@ private Node getLastElement() { } } + /* + * could have been left inside getElementN, but broken into a separate method for use + * by other methods if required + */ + private void validateIndex(int index) { + if ((index >= size) || (index < 0)) + throw new IndexOutOfBoundsException(); + } + /* * Return element at index n (not the data in that element) */ private Node getElementN(int index) { - if ((index >= size) || (index < 0)) - throw new IndexOutOfBoundsException(); + validateIndex(index); Node n = head; int i = -1; @@ -283,6 +292,39 @@ public void add(ItemType item) { ++size; } + /** + * Compares the specified object (a collection) with this collection for equality. + * + * Equal only if the lists are the same size, and each node equals the matching + * node in the alternate list. + * + * @param obj object to be compared for equality with this collection + * @return true if the specified other object is equal to this collection + */ + @Override + public boolean equals(Object obj) { + // https://docs.oracle.com/javase/7/docs/api/java/util/AbstractList.html#equals(java.lang.Object) + // object is not null, and it matches this class type + if (obj != null && obj.getClass() == this.getClass()) { + + List list = (List) obj; + + if (this.size != list.size()) + return false; + + ListIterator litA = this.listIterator(); + ListIterator litB = list.listIterator(); + while (litA.hasNext()) { + if (!litA.next().equals(litB.next())) + return false; + } + } else { + return false; + } + + return true; + } + /** * Removes a single instance of the specified item from this collection, * if it is present. diff --git a/src/edu/greenriver/sdev333/SinglyLinkedList.java b/src/edu/greenriver/sdev333/SinglyLinkedList.java index 93b1e3c..c84d31a 100644 --- a/src/edu/greenriver/sdev333/SinglyLinkedList.java +++ b/src/edu/greenriver/sdev333/SinglyLinkedList.java @@ -3,6 +3,16 @@ import java.util.Iterator; import java.util.ListIterator; +/** + * NOT TESTED - SEE DoublyLinkedList + * This class implements the List interface using a SinglyLinkedList. + * The code here is not complete, I finished implementing this + * interface using a DoublyLinkedList instead. + * + * @author Paul Woods + * @param + */ + public class SinglyLinkedList implements List { // FIELDS - what does a linked list actually have in it?? From fe3a7df0ca89190f6be9c1446034c7e5605b8927 Mon Sep 17 00:00:00 2001 From: Paul Woods Date: Fri, 3 Feb 2023 13:31:02 -0800 Subject: [PATCH 15/15] clarifying comments regarding assignment. --- src/Main.java | 3 +++ src/edu/greenriver/sdev333/DoublyLinkedList.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/Main.java b/src/Main.java index 2e8c3cc..51c098b 100644 --- a/src/Main.java +++ b/src/Main.java @@ -3,6 +3,9 @@ import java.util.ListIterator; /** + * Did the Level 1, Level 2, and Extras with the exception of the + * hashCode() method. + * * Main Class used to test functionality of ArrayList implementation. * Inside the main() method are comments and code regarding the setup * and testing for each given method. diff --git a/src/edu/greenriver/sdev333/DoublyLinkedList.java b/src/edu/greenriver/sdev333/DoublyLinkedList.java index f97c1c2..21c58ae 100644 --- a/src/edu/greenriver/sdev333/DoublyLinkedList.java +++ b/src/edu/greenriver/sdev333/DoublyLinkedList.java @@ -4,6 +4,9 @@ import java.util.ListIterator; /** + * Did the Level 1, Level 2, and Extras with the exception of the + * hashCode() method. + * * This class implements the List interface. Testing is done in the * Main class, and there were intial bugs found and then corrected, * esp wrt to the ListIterator class. I had to cycle through the