diff --git a/src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java b/src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java index ca32e28..93a8109 100644 --- a/src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java +++ b/src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java @@ -1,7 +1,94 @@ package com.zipcodewilmington.arrayutility; +import com.sun.org.apache.xpath.internal.operations.String; + +import java.io.OptionalDataException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + /** * Created by leon on 3/6/18. */ -public class ArrayUtility { + + +// created a generic class +public class ArrayUtility {// created a generic class + private T[] inputArray; + + public ArrayUtility(T[] inputArray) { + this.inputArray = inputArray; + } + + public Integer countDuplicatesInMerge(T[] arrayToMerge, T valueToEvaluate) { + Integer counter = 0; + for (int i = 0; i < inputArray.length; i++){ + if (inputArray[i].equals(valueToEvaluate)) { + counter++; + } + } + for (int j = 0; j < arrayToMerge.length; j++) { + if (arrayToMerge[j].equals(valueToEvaluate)) { + counter++; + } + + } + return counter; + } + + public T getMostCommonFromMerge (T[] arrayToMerge) { + T mostCommon = null; + + for (int i = 0; i < inputArray.length; i++) { + for (int j = 0; j < arrayToMerge.length;j++){ + if(inputArray[i] == arrayToMerge[j]){ + mostCommon = inputArray[i]; + } + } + } + return mostCommon; + } + + public Integer getNumberOfOccurrences( T valueToEvaluate) { + Integer counter = 0; + + for (int i = 0; i < inputArray.length; i++) { + if (inputArray[i].equals(valueToEvaluate)){ + counter++; + } + } + return counter; + + } + + public T[] removeValue( T valueToRemove) { + T[] newArray; + Integer counter = 0; + Integer remove = getNumberOfOccurrences(valueToRemove); + Integer newSize = inputArray.length - remove; + + newArray = Arrays.copyOf(inputArray, newSize); + for (int i = 0; i < inputArray.length; i++) { + if(inputArray[i] != valueToRemove){ + newArray[counter] = inputArray[i]; + counter++; + } + } + return newArray; + + } + + + + + + + + + + + + + } diff --git a/src/test/java/com/zipcodewilmington/arrayutility/RemoveValueTest.java b/src/test/java/com/zipcodewilmington/arrayutility/RemoveValueTest.java index d464896..446b71c 100644 --- a/src/test/java/com/zipcodewilmington/arrayutility/RemoveValueTest.java +++ b/src/test/java/com/zipcodewilmington/arrayutility/RemoveValueTest.java @@ -1,6 +1,6 @@ package com.zipcodewilmington.arrayutility; -import com.zipcodewilmington.UnitTestingUtils; +//import com.zipcodewilmington.UnitTestingUtils; import org.junit.Test; /**