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..ce1cf9f
--- /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..b2526f7
--- /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/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ 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..2b9c9ba
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,1054 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ arraylist(
+ remove(
+ toArray
+ contains(
+ to
+ toarray
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ DEFINITION_ORDER
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ No facets are configured
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 9.0
+
+
+
+
+
+
+
+
+
+
+
+ generics
+
+
+
+
+
+
+
+
+
+
+
+
+ Maven: junit:junit:4.12
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.notes b/.notes
new file mode 100644
index 0000000..ab56bc8
--- /dev/null
+++ b/.notes
@@ -0,0 +1,7 @@
++ add()
++ get() -> E
++ remove()
++ set()
++ clear()
++ isEmpty() -> boolean
++ contains() -> boolean
diff --git a/generics.iml b/generics.iml
new file mode 100644
index 0000000..10ba022
--- /dev/null
+++ b/generics.iml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 73be9cd..1a88bb5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,15 +13,14 @@
org.apache.maven.plugins
maven-compiler-plugin
- 1.7
- 1.7
+ 1.9
+ 1.9
-
junit
junit
diff --git a/src/main/java/.deleteme b/src/main/java/.deleteme
deleted file mode 100644
index e69de29..0000000
diff --git a/src/main/java/GreatValueArrayList.java b/src/main/java/GreatValueArrayList.java
new file mode 100644
index 0000000..a41e182
--- /dev/null
+++ b/src/main/java/GreatValueArrayList.java
@@ -0,0 +1,137 @@
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Objects;
+
+/**
+ * filename:
+ * project: generics
+ * author: https://github.com/vvmk
+ * date: 3/8/18
+ */
+public class GreatValueArrayList {
+ private static final int fDEFAULT_CAPACITY = 10;
+ private Object[] array;
+ private int numberOfElements;
+
+ public GreatValueArrayList() {
+ this(fDEFAULT_CAPACITY);
+ }
+
+ public GreatValueArrayList(int startingCapacity) {
+ array = new Object[startingCapacity];
+ numberOfElements = 0;
+ }
+
+ /**
+ * Not cheating.
+ */
+ public GreatValueArrayList(Collection extends E> c) {
+ array = c.toArray();
+ numberOfElements = array.length;
+ }
+
+ public int size() {
+ return numberOfElements;
+ }
+
+ public int getCapacity() {
+ return array.length;
+ }
+
+ public void add(E e) {
+ if (numberOfElements == array.length)
+ grow();
+
+ array[numberOfElements] = e;
+ numberOfElements++;
+ }
+
+ /**
+ * increase array size + 2 * 2
+ */
+ protected void grow() {
+ grow((numberOfElements + 2) * 2);
+ }
+
+ /**
+ * increase array size by given capacity
+ *
+ * @param capacity
+ */
+ protected void grow(int capacity) {
+ array = Arrays.copyOf(array, capacity);
+ }
+
+ @SuppressWarnings("unchecked")
+ public E get(int index) {
+ Objects.checkIndex(index, numberOfElements); // actually throws a runtime exception upon failure!!!
+ return (E) array[index];
+ }
+
+ public void remove(Object o) {
+ for (int i = 0; i < numberOfElements; i++) {
+ if (array[i].equals(o))
+ remove(i);
+ }
+ }
+
+ // fast remove, stay private
+ private void remove(int index) {
+ Objects.checkIndex(index, numberOfElements);
+
+ assert (index < numberOfElements);
+
+ int shifts = numberOfElements - index - 1;
+ System.arraycopy(array, index + 1, array, index, shifts);
+
+ array[--numberOfElements] = null;
+ }
+
+ public void clear() {
+ Arrays.fill(array, null);
+ numberOfElements = 0;
+ }
+
+ public boolean isEmpty() {
+ return numberOfElements == 0;
+ }
+
+ public boolean contains(E e) {
+ if (isEmpty())
+ return false;
+
+ for (int i = 0; i < numberOfElements; i++) {
+ if (array[i].equals(e))
+ return true;
+ }
+ return false;
+ }
+
+ public boolean containsAll(Collection extends E> c) {
+ for (E e : c) {
+ if (!contains(e))
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return Arrays.toString(array);
+ }
+
+ @SuppressWarnings("unchecked")
+ public T[] toArray(T[] a) {
+ if (a.length < numberOfElements)
+ return (T[]) Arrays.copyOf(array, numberOfElements, a.getClass());
+
+ // this is here not because I have ever needed it, but because we're cloning ArrayList and it does this.
+ System.arraycopy(array, 0, a, 0, numberOfElements);
+
+ return a;
+ }
+
+ public Object[] toArray() {
+ return Arrays.copyOf(array, numberOfElements);
+ }
+}
diff --git a/src/main/java/GreatValueSet.java b/src/main/java/GreatValueSet.java
new file mode 100644
index 0000000..31f52f8
--- /dev/null
+++ b/src/main/java/GreatValueSet.java
@@ -0,0 +1,74 @@
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * filename:
+ * project: generics
+ * author: https://github.com/vvmk
+ * date: 3/8/18
+ */
+public class GreatValueSet {
+ private GreatValueArrayList arrayList;
+
+ public GreatValueSet() {
+ arrayList = new GreatValueArrayList<>();
+ }
+
+ public GreatValueSet(int startingCapacity) {
+ arrayList = new GreatValueArrayList<>(startingCapacity);
+ }
+
+ public GreatValueSet(Collection extends E> c) {
+ arrayList = new GreatValueArrayList<>(c);
+ }
+
+ public void add(E e) {
+ if (arrayList.isEmpty())
+ arrayList.add(e);
+
+ if (!arrayList.contains(e))
+ arrayList.add(e);
+ }
+
+ public void addAll(Collection extends E> c) {
+ for (E e : c)
+ add(e);
+ }
+
+ public void clear() {
+ arrayList.clear();
+ }
+
+ public boolean contains(E e) {
+ return arrayList.contains(e);
+ }
+
+ public boolean containsAll(Collection extends E> c) {
+ return arrayList.containsAll(c);
+ }
+
+ public boolean isEmpty() {
+ return arrayList.isEmpty();
+ }
+
+ public void remove(E e) {
+ arrayList.remove(e);
+ }
+
+ public void removeAll(Collection> c) {
+ for (Object o : c)
+ arrayList.remove(o);
+ }
+
+ public int size() {
+ return arrayList.size();
+ }
+
+ public Object[] toArray() {
+ return arrayList.toArray();
+ }
+
+ public T[] toArray(T[] a) {
+ return arrayList.toArray(a);
+ }
+}
diff --git a/src/test/java/.deleteme b/src/test/java/.deleteme
deleted file mode 100644
index e69de29..0000000
diff --git a/src/test/java/GreatValueArrayListTest.java b/src/test/java/GreatValueArrayListTest.java
new file mode 100644
index 0000000..c3a2523
--- /dev/null
+++ b/src/test/java/GreatValueArrayListTest.java
@@ -0,0 +1,143 @@
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+/**
+ * filename:
+ * project: generics
+ * author: https://github.com/vvmk
+ * date: 3/8/18
+ */
+public class GreatValueArrayListTest {
+ GreatValueArrayList greatValueArrayList;
+
+ @Before
+ public void setUp() {
+ greatValueArrayList = new GreatValueArrayList<>();
+ }
+
+ @Test
+ public void addWithEnoughSpace() {
+ int expected = greatValueArrayList.size() + 1;
+ greatValueArrayList.add(1);
+ int actual = greatValueArrayList.size();
+
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void addToFullArray() {
+ greatValueArrayList = new GreatValueArrayList<>(1);
+
+ int expectedSize = greatValueArrayList.size() + 1;
+ int expectedCapacity = greatValueArrayList.getCapacity();
+
+ greatValueArrayList.add(1);
+
+ int actualSize = greatValueArrayList.size();
+ int actualCapacity = greatValueArrayList.getCapacity();
+
+ Assert.assertEquals(expectedCapacity, actualCapacity);
+ Assert.assertEquals(expectedSize, actualSize);
+ }
+
+ @Test
+ public void ensureCapacity() {
+ greatValueArrayList = new GreatValueArrayList<>(0);
+ int expected = (greatValueArrayList.getCapacity() + 2) * 2;
+
+ greatValueArrayList.grow();
+ int actual = greatValueArrayList.getCapacity();
+
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void resizeArray() {
+ int newCapacity = 100;
+ greatValueArrayList.grow(newCapacity);
+ int actual = greatValueArrayList.getCapacity();
+
+ Assert.assertEquals(newCapacity, actual);
+ }
+
+ @Test
+ public void get() {
+ Integer expected = 4;
+ greatValueArrayList.add(expected);
+ Integer actual = greatValueArrayList.get(0);
+
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void remove() {
+ Integer[] input = {1, 2, 3, 4, 5};
+ Integer valueToRemove = 4;
+ greatValueArrayList = new GreatValueArrayList<>(Arrays.asList(input));
+ greatValueArrayList.remove(valueToRemove);
+ Integer[] actual = greatValueArrayList.toArray(new Integer[0]);
+
+ for (Integer i : actual) {
+ if (i.equals(4))
+ Assert.fail();
+ }
+ }
+
+ @Test
+ public void clear() {
+ Integer[] input = {1, 2, 3, 4, 5};
+ greatValueArrayList = new GreatValueArrayList<>(Arrays.asList(input));
+
+ Assert.assertEquals(greatValueArrayList.size(), input.length);
+
+ greatValueArrayList.clear();
+ int expected = 0;
+ int actual = greatValueArrayList.size();
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void isEmptyTrue() {
+ greatValueArrayList = new GreatValueArrayList<>(0);
+ Assert.assertTrue(greatValueArrayList.isEmpty());
+ }
+
+ @Test
+ public void isEmptyFalse() {
+ Integer[] input = {1, 2, 3, 4, 5};
+ greatValueArrayList = new GreatValueArrayList<>(Arrays.asList(input));
+
+ Assert.assertFalse(greatValueArrayList.isEmpty());
+ }
+
+ @Test
+ public void containsTrue() {
+ Integer[] input = {1, 2, 3, 4, 5};
+ Integer inArray = input[0];
+ greatValueArrayList = new GreatValueArrayList<>(Arrays.asList(input));
+
+ Assert.assertTrue(greatValueArrayList.contains(inArray));
+ }
+
+ @Test
+ public void containsFail() {
+ Integer[] input = {1, 2, 3, 4, 5};
+ Integer notInArray = 6;
+ greatValueArrayList = new GreatValueArrayList<>(Arrays.asList(input));
+
+ Assert.assertFalse(greatValueArrayList.contains(notInArray));
+ }
+
+ @Test
+ public void testOOB() {
+ try {
+ greatValueArrayList.get(75);
+ Assert.fail();
+ } catch (IndexOutOfBoundsException oobe) {
+ oobe.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/GreatValueSetTest.java b/src/test/java/GreatValueSetTest.java
new file mode 100644
index 0000000..dc44f61
--- /dev/null
+++ b/src/test/java/GreatValueSetTest.java
@@ -0,0 +1,103 @@
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+/**
+ * filename:
+ * project: generics
+ * author: https://github.com/vvmk
+ * date: 3/8/18
+ */
+public class GreatValueSetTest {
+ GreatValueSet set;
+
+ @Before
+ public void setup() {
+ set = new GreatValueSet<>();
+ }
+
+ @Test
+ public void addNewElement() {
+ Integer[] input = {1, 2};
+ Integer addMe = 3;
+ int[] eArray = {1, 2, 3};
+ String expected = Arrays.toString(eArray);
+
+ set = new GreatValueSet<>(Arrays.asList(input));
+ set.add(addMe);
+ String actual = Arrays.toString(set.toArray());
+
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void addDuplicateElement() {
+ Integer[] input = {1, 2, 3};
+ Integer addMe = 3;
+ int[] eArray = {1, 2, 3};
+ String expected = Arrays.toString(eArray);
+
+ set = new GreatValueSet<>(Arrays.asList(input));
+ set.add(addMe);
+ String actual = Arrays.toString(set.toArray());
+
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void addAll() {
+ Integer[] input = {1, 2, 3};
+ Integer[] addMe = {4, 5, 6};
+ Integer[] expectedArray = {1, 2, 3, 4, 5, 6};
+ String expected = Arrays.toString(expectedArray);
+
+ set = new GreatValueSet<>(Arrays.asList(input));
+ set.addAll(Arrays.asList(addMe));
+
+ Integer[] actualArray = set.toArray(new Integer[0]);
+
+ Arrays.sort(actualArray);
+ Arrays.sort(expectedArray);
+
+ String actual = Arrays.toString(actualArray);
+
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void containsAllYes() {
+ Integer[] input = {1, 2, 3};
+ Integer[] checkMe = {1, 2};
+
+ set = new GreatValueSet<>(Arrays.asList(input));
+
+ Assert.assertTrue(set.containsAll(Arrays.asList(checkMe)));
+ }
+
+ @Test
+ public void containsAllNope() {
+ Integer[] input = {1, 2, 3, 4, 5};
+ Integer[] checkMe = {1, 2, 3, 4, 6};
+
+ set = new GreatValueSet<>(Arrays.asList(input));
+
+ Assert.assertFalse(set.containsAll(Arrays.asList(checkMe)));
+ }
+
+ @Test
+ public void removeAll() {
+ Integer[] input = {1, 2, 3};
+ Integer[] removeUs = {2, 3};
+ Integer[] expectedArray = {1};
+
+ set = new GreatValueSet<>(Arrays.asList(input));
+ set.removeAll(Arrays.asList(removeUs));
+
+ String expected = Arrays.toString(expectedArray);
+ String actual = Arrays.toString(set.toArray(new Integer[0]));
+
+ Assert.assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/ProjectTestSuite.java b/src/test/java/ProjectTestSuite.java
new file mode 100644
index 0000000..0ee9b21
--- /dev/null
+++ b/src/test/java/ProjectTestSuite.java
@@ -0,0 +1,16 @@
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * filename:
+ * project: generics
+ * author: https://github.com/vvmk
+ * date: 3/9/18
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ GreatValueArrayListTest.class,
+ GreatValueSetTest.class
+})
+public class ProjectTestSuite {
+}