From c469edd42e3723697224da35339597832b98796f Mon Sep 17 00:00:00 2001 From: Joshua Wurdemann Date: Thu, 8 Mar 2018 15:51:36 -0500 Subject: [PATCH 1/6] stubed most of arraylist methods but not all --- .idea/.name | 1 + .idea/compiler.xml | 16 + .idea/libraries/Maven__junit_junit_4_12.xml | 13 + .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 + .idea/misc.xml | 13 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 345 ++++++++++++++++++ generics.iml | 16 + src/main/java/ArrayList.java | 41 +++ 10 files changed, 472 insertions(+) create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/libraries/Maven__junit_junit_4_12.xml create mode 100644 .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 generics.iml create mode 100644 src/main/java/ArrayList.java diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..1f58a0f --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +generics \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..c20d346 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml new file mode 100644 index 0000000..d411041 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e8942bd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ca63f44 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..3da76d6 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,345 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -273,7 +267,7 @@ - + - + - + - - - - - + + + + + - - - - - + + + + + @@ -485,20 +479,12 @@ - - - - - - - - - @@ -520,41 +506,50 @@ + + + + + + + + + - - + - + - - - - - - - - - - - - - + + + + + + + + + + + + + - - + + - + - - + + @@ -570,50 +565,120 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + + - - + + + - - + + - + - - - + + - - + + @@ -628,8 +693,8 @@ - - + + @@ -651,31 +716,46 @@ - + - - - - - - - - + + + - + - - + + - + + + + + + + + + + + + + + + + + + + + + - - + + diff --git a/src/main/java/MySet.java b/src/main/java/MySet.java index ca028a9..aa12e57 100644 --- a/src/main/java/MySet.java +++ b/src/main/java/MySet.java @@ -1,28 +1,35 @@ +import com.sun.tools.classfile.Opcode; + import java.util.Set; public class MySet extends MyCollections { + public MySet() { + super(DEFAULT_SIZE); + } - public MySet(){ - super(DEFAULT_SIZE); - } - - @Override - public boolean add(E theObject){ + @Override + public boolean add(E theObject) { + boolean added = false; + if (!contains(theObject)) + super.add(theObject); + added = true; + return added; + } - return false; - } -/*It is reflexive: for any non-null reference value x, x.equals(x) should return true. -It is symmetric: for any non-null reference values x and y, x.equals(y) should - return true if and only if y.equals(x) returns true. -It is transitive: for any non-null reference values x, y, and z, if x.equals(y) -returns true and y.equals(z) returns true, then x.equals(z) should return true. -It is consistent: for any non-null reference values x and y, multiple invocations of -x.equals(y) consistently return true or consistently return false, provided no -information used in equals comparisons on the objects is modified.*/ + @Override + public boolean equals(Object theObject) { + //check to see if TheObject is an instance of the set + // check to see if sizes are the same + // check to see if the one set contains all the same object + if (!(theObject instanceof MySet)) { + return false; + } + if ((((MySet) theObject).getSize() != getSize())) + if (!((MySet) theObject).contains(theObject)) { + return false; + } - @Override - public boolean equals(Object theObject) { - return false; - } + return theObject.equals(getNumbers()); + } } diff --git a/src/test/java/MySetTest.java b/src/test/java/MySetTest.java new file mode 100644 index 0000000..d3e084d --- /dev/null +++ b/src/test/java/MySetTest.java @@ -0,0 +1,40 @@ +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class MySetTest { + private MySet theSet; + + @Before + public void setUp() throws Exception { + theSet = new MySet<>(); + for (int i = 0; i <= 10; i++) { + theSet.add(i); + } + } + + @Test + public void addTest() { + theSet.add(11); + int expected = 12; + int acutal = theSet.getSize(); + + Assert.assertEquals(expected, acutal); + } + + @Test + public void addNoDuplicatesTest() { + theSet.add(10); + int expected = 11; + int acutal = theSet.getSize(); + + Assert.assertEquals(expected, acutal); + } + + + @Test + public void equals() { + } +} \ No newline at end of file