diff --git a/pom.xml b/pom.xml index 67014e6..fe5de65 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,7 @@ 1.8 1.8 + 1.2.30 @@ -21,7 +22,67 @@ junit 4.12 + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-test + ${kotlin.version} + test + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + 1.8 + + + + org.apache.maven.plugins + maven-compiler-plugin + + + compile + compile + + compile + + + + testCompile + test-compile + + testCompile + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java b/src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java deleted file mode 100644 index ca32e28..0000000 --- a/src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.zipcodewilmington.arrayutility; - -/** - * Created by leon on 3/6/18. - */ -public class ArrayUtility { -} diff --git a/src/main/java/com/zipcodewilmington/arrayutility/com/zipcodewilmington/arrayutility/ArrayUtility.java b/src/main/java/com/zipcodewilmington/arrayutility/com/zipcodewilmington/arrayutility/ArrayUtility.java new file mode 100644 index 0000000..eb85c97 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/arrayutility/com/zipcodewilmington/arrayutility/ArrayUtility.java @@ -0,0 +1,82 @@ +package com.zipcodewilmington.arrayutility; + +import java.util.ArrayList; +import java.util.Arrays; + +/** + * Created by leon on 3/6/18. + */ +public class ArrayUtility{ + + T[] array; + + + public ArrayUtility(T[] inputArray) { + this.array = inputArray; + } + + + public int getNumberOfOccurrences(T valueToEvaluate){ + int count = 0; + for (int i = 0; i < array.length; i ++){ + if (array[i].equals(valueToEvaluate)){ + count++; + } + } + return count; + } + + public int countDuplicatesInMerge(T[] inputArray, T valueToEvaluate){ + int count = 0; + for (T element : inputArray){ + if (element.equals(valueToEvaluate)){ + count++; + } + } + for (T element : this.array){ + if (element.equals(valueToEvaluate)){ + count++; + } + } + return count; + } + public T getMostCommonFromMerge(T[] inputArray){ + int currentCount = 1; + int mostCommonCount; + + T mostCommon = inputArray[0]; + T tempCount; + + for(int i = 1; i < inputArray.length-1; i++){ + tempCount = inputArray[i]; + mostCommonCount = 0; + + for (int j = 0; j < inputArray.length; j++){ + if (tempCount == inputArray[j]){ + mostCommonCount++; + } + if (mostCommonCount > currentCount){ + mostCommon = tempCount; + } + } + + } + return mostCommon; + } + public T[] removeValue(T valueToRemove){ + int newSize = array.length - getNumberOfOccurrences(valueToRemove); + + T[] result = Arrays.copyOf(this.array, newSize); + int index = 0; + + for (T value : this.array){ + if (!value.equals(valueToRemove)){ + + result[index] = value; + index++; + } + } + return result; + } +} + diff --git a/src/test/java/com/zipcodewilmington/arrayutility/ArrayUtilityTestSuite.java b/src/test/java/com/zipcodewilmington/arrayutility/ArrayUtilityTestSuite.java index 8413aae..7efa337 100644 --- a/src/test/java/com/zipcodewilmington/arrayutility/ArrayUtilityTestSuite.java +++ b/src/test/java/com/zipcodewilmington/arrayutility/ArrayUtilityTestSuite.java @@ -7,13 +7,13 @@ * Created by leon on 3/1/18. * The purpose of this class is to test all classes within this package */ -@RunWith(Suite.class) - -@Suite.SuiteClasses({ - CountDuplicatesInMergeTest.class, - GetMostCommonFromMergeTest.class, - GetNumberOfOccurrencesTest.class, - RemoveValueTest.class -}) -public class ArrayUtilityTestSuite { -} +//@RunWith(Suite.class) +// +//@Suite.SuiteClasses({ +// CountDuplicatesInMergeTest.class, +// GetMostCommonFromMergeTest.class, +// GetNumberOfOccurrencesTest.class, +// RemoveValueTest.class +//}) +//public class ArrayUtilityTestSuite { +//} diff --git a/src/test/java/com/zipcodewilmington/arrayutility/RemoveValueTest.java b/src/test/java/com/zipcodewilmington/arrayutility/RemoveValueTest.java index d464896..1b82da0 100644 --- a/src/test/java/com/zipcodewilmington/arrayutility/RemoveValueTest.java +++ b/src/test/java/com/zipcodewilmington/arrayutility/RemoveValueTest.java @@ -1,6 +1,5 @@ package com.zipcodewilmington.arrayutility; -import com.zipcodewilmington.UnitTestingUtils; import org.junit.Test; /**