diff --git a/.gitignore b/.gitignore
index aa241d3..f5c955d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,8 @@
.settings
.project
+.idea
+
# Mobile Tools for Java (J2ME)
.mtj.tmp/
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..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/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/generics.iml b/generics.iml
new file mode 100644
index 0000000..9717c26
--- /dev/null
+++ b/generics.iml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/MyArrayList.java b/src/main/java/MyArrayList.java
new file mode 100644
index 0000000..651f58f
--- /dev/null
+++ b/src/main/java/MyArrayList.java
@@ -0,0 +1,154 @@
+import java.util.Arrays;
+
+public class MyArrayList {
+
+ private int size;
+ private static final int DEFAULT_CAPACITY = 10;
+ private Object[] inputArray;
+
+
+ public MyArrayList() {
+ this(DEFAULT_CAPACITY);
+ }
+
+ public MyArrayList(int capacity) {
+ this.inputArray = new Object[capacity];
+ this.size = 0;
+ }
+
+ /**
+ * @return current number of elements in this list
+ */
+ public int size() {
+ return size;
+ }
+
+ /**
+ * @return true if this list contains no elements
+ */
+ public Boolean isEmpty() {
+ if (this.size == 0) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Increases the capacity of the ArrayList instance, if necessary,
+ * to ensure that it can hold at least the number of elements
+ */
+ private void ensureCapacity() {
+ if (size >= this.inputArray.length) {
+ int newCapacity = this.inputArray.length + DEFAULT_CAPACITY;
+ this.inputArray = Arrays.copyOf(this.inputArray, newCapacity);
+ }
+ }
+
+ /**
+ * Appends the specified element to the end of this list
+ *
+ * @param addMe element to be appended to this list
+ * @return true if appended and false if not appended
+ */
+ public Boolean add(E addMe) {
+ ensureCapacity();
+ this.inputArray[size++] = addMe;
+ return true;
+ }
+
+ /**
+ * Inserts the specified element at the specified position in this list.
+ * Shifts the element currently at that position(if any) and any subsequent
+ * elements to the right(adds 1 to the other indices).
+ *
+ * @param index at which specified element is to be inserted
+ * @param addMe element to be inserted to this list
+ * @return true if appended and false if not appended
+ */
+ public Boolean add(int index, E addMe) {
+ if (index < 0 || index >= size()) {
+ throw new IndexOutOfBoundsException("Index is too large or negative");
+ }
+ int length = size() - index;
+ ensureCapacity();
+ System.arraycopy(this.inputArray, index, this.inputArray, index + 1, length);
+ this.inputArray[index] = addMe;
+ return true;
+ }
+
+ /**
+ * Removes the element at the specified position in this list.
+ * Shifts any subsequent elements to the left(subtracts one from their indices).
+ *
+ * @param index of element to be removed
+ * @return the element that was removed from the list
+ */
+ @SuppressWarnings("unchecked")
+ public E remove(int index) {
+ if (index < 0 || index >= size()) {
+ throw new IndexOutOfBoundsException("Index is too large or negative");
+ }
+ E storePreviousElement = (E) this.inputArray[index];
+ int length = size() - index;
+ if (length > 0) {
+ System.arraycopy(this.inputArray, index + 1, this.inputArray, index, length);
+ this.inputArray[size--] = null;
+ }
+ return storePreviousElement;
+ }
+
+ /**
+ * Returns the element at the specified position in this list
+ *
+ * @param index of element to return
+ * @return element at the specified position in this list
+ */
+ @SuppressWarnings("unchecked")
+ public E get(Integer index) {
+ if (index < 0 || index >= size()) {
+ throw new IndexOutOfBoundsException("Index is too large or negative");
+ }
+ return (E) this.inputArray[index];
+ }
+
+ /**
+ * Removes all of the elements from this list
+ * The list will be empty after this call returns.
+ */
+ public void clear() {
+ this.inputArray = new Object[DEFAULT_CAPACITY];
+ this.size = 0;
+ }
+
+ /**
+ * @param element to be checked
+ * @return true if list contains the specified element.
+ */
+ public Boolean contains(E element) {
+ for (Object obj : this.inputArray) {
+ if (obj != null && obj.equals(element))
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Replaces the element at the specified position in this list with the specified element.
+ *
+ * @param index of the element to replace
+ * @param element to be stored at the specified position
+ * @return the element previously at the specified position
+ */
+ @SuppressWarnings("unchecked")
+ public E set(int index, E element) {
+ if (index < 0 || index >= size()) {
+ throw new IndexOutOfBoundsException("Index is too large or negative");
+ }
+ E storePreviousElement = (E) this.inputArray[index];
+ this.inputArray[index] = element;
+ return storePreviousElement;
+ }
+
+}
+
+
diff --git a/src/main/java/MySet.java b/src/main/java/MySet.java
new file mode 100644
index 0000000..8db4dde
--- /dev/null
+++ b/src/main/java/MySet.java
@@ -0,0 +1,253 @@
+import java.lang.reflect.Array;
+import java.util.Arrays;
+import java.util.Collection;
+
+
+public class MySet {
+
+ private static final int DEFAULT_CAPACITY = 10;
+
+ private Object[] inputArray;
+ private int size;
+
+ public MySet() {
+ this(DEFAULT_CAPACITY);
+ }
+
+ public MySet(int capacity) {
+ this.inputArray = new Object[capacity];
+ this.size = 0;
+ }
+
+
+ /**
+ * Get set size
+ *
+ * @return current number of elements in this list
+ */
+ public int size() {
+ return this.size;
+ }
+
+ /**
+ * Add Object o to set
+ *
+ * @param element - object to be added to this set
+ * @return true if this set did not already contain the specified element. false if set already contains element
+ * and leaves the set unchanged
+ */
+ public boolean add(E element) {
+ if (element == null) {
+ throw new NullPointerException("Specified element can't be null");
+ }
+ if (this.contains(element)) {
+ return false;
+ }
+
+ this.ensureCapacity();
+ this.inputArray[this.size++] = element;
+
+ return true;
+ }
+
+ /**
+ * Check if set is empty
+ *
+ * @return true if this set contains no elements
+ */
+ public boolean isEmpty() {
+ return this.size == 0;
+ }
+
+ /**
+ * @param element to be checked
+ * @return true if this set contains the specified element
+ */
+ public Boolean contains(E element) {
+ if (element == null) {
+ throw new NullPointerException("Specified element can't be null");
+ }
+ for (int i = 0; i < this.size; i++) {
+ if (this.inputArray[i].equals(element)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Removes the specified element from this set if it is present
+ *
+ * @param element - element to be removed from this set, if present
+ * @return true if this set contained the specified element
+ */
+ public boolean remove(E element) {
+ if (element == null) {
+ throw new NullPointerException("Specified element can't be null");
+ }
+ boolean canRemove = false;
+ int indexOf = 0;
+ for (int i = 0; i < this.inputArray.length; i++) {
+ if (this.inputArray[i] != null && this.inputArray[i].equals(element)) {
+ indexOf = i;
+ canRemove = true;
+ break;
+ }
+ }
+
+ if (canRemove) {
+ this.inputArray[indexOf] = null;
+ this.inputArray = shiftAllNullsToEnd(this.inputArray);
+ this.size--;
+ }
+
+ return canRemove;
+ }
+
+ /**
+ * Adds all of the elements in the specified collection to this set if they're not already present
+ * returns false if ANY element could not be added. If the specified collection is also a set, the
+ * addAll operation effectively modifies this set so that its value is the union of the two sets.
+ *
+ * @param container collection containing elements to be added to this set
+ * @return true if this set changed as a result of the call
+ */
+ public boolean addAll(Collection container) {
+ boolean allAdded = container.size() > 0;
+ for (E obj : container) {
+ if (!this.add(obj)) {
+ allAdded = false;
+ }
+ }
+ return allAdded;
+ }
+
+ /**
+ * @param container collection to be checked for containment in this set
+ * @return true if this set contains all of the elements of the specified collection.
+ * If the specified collection is also a set, this method returns true if it is a subset of this set.
+ */
+ public boolean containsAll(Collection container) {
+ for (E obj : container) {
+ if (!this.contains(obj)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Remove all elements from set except those in c, keeps matching elements
+ *
+ * @param container collection containing elements to be retained in this set
+ * @return true if this set changed as a result of the call.
+ */
+ public boolean retainAll(Collection container) {
+ for (int i = 0; i < this.inputArray.length; i++) {
+ if (!container.contains(this.inputArray[i])) {
+ this.inputArray[i] = null;
+ this.size--;
+ }
+ }
+ this.inputArray = shiftAllNullsToEnd(this.inputArray);
+ return true;
+ }
+
+ /**
+ * Remove all elements that are also in c
+ * @param container collection containing elements to be removed from this set
+ * @return true if ANY elements are removed
+ */
+ public boolean removeAll(Collection container) {
+ boolean anyRemoved = false;
+ for (E obj : container) {
+ if (this.remove(obj)) {
+ anyRemoved = true;
+ }
+ }
+ return anyRemoved;
+ }
+
+ /**
+ * Removes all of the elements from this set
+ * The set will be empty after this call returns.
+ */
+ public void clear() {
+ this.inputArray = new Object[DEFAULT_CAPACITY];
+ this.size = 0;
+ }
+
+ /**
+ * Get array representation of set
+ * makes a copy of input array and removes all the nulls.
+ *
+ * @return array with only elements
+ */
+ @SuppressWarnings("unchecked")
+ public E[] toArray(E[] in) {
+ Object[] t = trimTrailingNull(this.inputArray);
+ return (E[]) Arrays.copyOf(t, t.length, in.getClass());
+ }
+
+ /**
+ * @param arr array to be altered assumed that all non-null values are contiguous starting at index 0
+ * @return array with with trailing nulls removed
+ * Do not make generic, internal to class,
+ */
+ @SuppressWarnings("unchecked")
+ private static Object[] trimTrailingNull(Object[] arr) {
+ int lastNotNull = 0;
+ for (int i = 0; i < arr.length; i++) {
+ if (arr[i] != null) {
+ lastNotNull++;
+ } else {
+ break;
+ }
+ }
+ if (lastNotNull == 0) {
+ return new Object[0];
+ }
+
+ Object[] trimmed = new Object[lastNotNull];
+ for (int i = 0; i < lastNotNull; i++) {
+ trimmed[i] = arr[i];
+ }
+
+ return trimmed;
+ }
+
+ /**
+ * Shift all null values to the end and make non-null values contiguous starting at index 0
+ *
+ * @param arr array to be altered
+ * @return array altered
+ * Do not make generic, internal to class, everything internal is object, everything external is type
+ */
+ private static Object[] shiftAllNullsToEnd(Object[] arr) {
+ int j = 0;
+ Object[] result = new Object[arr.length];
+ for (int i = 0; i < arr.length; i++) {
+ if (arr[i] != null) {
+ result[j++] = arr[i];
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Increases the capacity of the backing array, if necessary,
+ * to ensure that it can hold at least the number of elements
+ */
+ private void ensureCapacity() {
+ if (this.size >= this.inputArray.length) {
+ int newCapacity = this.inputArray.length + DEFAULT_CAPACITY;
+ this.inputArray = Arrays.copyOf(this.inputArray, newCapacity);
+ }
+ }
+
+}
+
+
+
+
diff --git a/src/test/java/TestMyArrayList.java b/src/test/java/TestMyArrayList.java
new file mode 100644
index 0000000..94f991a
--- /dev/null
+++ b/src/test/java/TestMyArrayList.java
@@ -0,0 +1,450 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestMyArrayList {
+ //---------------Test Constructor
+ @Test
+ public void testConstructorDefaultSize() {
+ int expectedElementCount = 0;
+ MyArrayList genericUtility = new MyArrayList<>();
+
+ int actualLength = genericUtility.size();
+
+ Assert.assertEquals(expectedElementCount, actualLength);
+ }
+
+ @Test
+ public void testConstructorSizeIncrease() {
+ int expectedSize = 3;
+ MyArrayList genericUtility = new MyArrayList<>();
+ genericUtility.add("this");
+ genericUtility.add("that");
+ genericUtility.add("andTheOtherThing");
+
+ int actualLength = genericUtility.size();
+
+ Assert.assertEquals(expectedSize, actualLength);
+ }
+
+ //---------------Test isEmpty
+ @Test
+ public void testIsSizeEmptyReturnsFalse() {
+ MyArrayList genericUtility = new MyArrayList<>();
+ genericUtility.add("this");
+ genericUtility.add("that");
+ genericUtility.add("andTheOtherThing");
+
+ Boolean actualElements = genericUtility.isEmpty();
+
+ Assert.assertEquals(false, actualElements);
+ }
+
+ @Test
+ public void testIsSizeEmptyReturnsTrue() {
+ MyArrayList genericUtility = new MyArrayList<>();
+
+ Boolean actualElements = genericUtility.isEmpty();
+
+ Assert.assertEquals(true, actualElements);
+ }
+
+
+ //---------------Test add append
+ @Test
+ public void testAddIntegerExpectTrue() {
+ Integer addMe = 25;
+ MyArrayList genericUtility = new MyArrayList<>();
+
+ Boolean actual = genericUtility.add(addMe);
+
+ Assert.assertTrue(actual);
+ }
+
+ @Test
+ public void testAddLongExpectTrue() {
+ Long addMe = 25L;
+ MyArrayList genericUtility = new MyArrayList<>();
+
+ Boolean actual = genericUtility.add(addMe);
+
+ Assert.assertTrue(actual);
+ }
+
+ @Test
+ public void testAddStringExpectTrue() {
+ String addMe = "last";
+ MyArrayList genericUtility = new MyArrayList<>();
+
+ Boolean actual = genericUtility.add(addMe);
+
+ Assert.assertTrue(actual);
+ }
+
+ @Test
+ public void testAddObjectExpectTrue() {
+ Object addMe = "last";
+ MyArrayList