shakila 6 лет назад
Родитель
Сommit
fdbf0eb917

+ 50
- 4
src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java Просмотреть файл

@@ -1,7 +1,53 @@
1 1
 package com.zipcodewilmington.arrayutility;
2
+import java.util.Arrays;
3
+import java.util.HashMap;
4
+import java.util.stream.Stream;
2 5
 
3
-/**
4
- * Created by leon on 3/6/18.
5
- */
6
-public class ArrayUtility {
6
+public class ArrayUtility <T> {
7
+    private T[] inputArray;
8
+
9
+    public ArrayUtility(){}
10
+    public ArrayUtility(T[] inputArray) {
11
+        this.inputArray = (T[]) inputArray;
12
+    }
13
+
14
+    public T getMostCommonFromMerge(T[] arrayToMerge) {
15
+        T[] mergeArray = Arrays.copyOf(inputArray, inputArray.length + arrayToMerge.length);
16
+        for(int i = 0; i<mergeArray.length; i++){
17
+            mergeArray[i+ inputArray.length] = arrayToMerge[i];
18
+        }
19
+
20
+        HashMap<T, Integer> repeats = new HashMap<>();
21
+        Integer mostCommon = 0;
22
+        for (int i = 0; i < mergeArray.length; i++) {
23
+            int count = 0;
24
+            for (int j = 0; j < mergeArray.length; j++) {
25
+                if (mergeArray[i] == mergeArray[j]) {
26
+                    count++;
27
+                }
28
+            }
29
+
30
+            if (count > 1) {
31
+                if (!repeats.containsKey(mergeArray[i])) {
32
+                    repeats.put(mergeArray[i], count);
33
+                    mostCommon += count;
34
+                }
35
+            }
36
+        }
37
+        T dupe = (T) repeats.get(0);
38
+        return dupe;
39
+    }
40
+
41
+
42
+    public T[] removeValue(T valueToRemove) {
43
+        return (T[]) inputArray;
44
+    }
45
+
46
+    public Integer countDuplicatesInMerge(T[] arrayToMerge, T valueToEvaluate) {
47
+        return null;
48
+    }
49
+
50
+    public Integer getNumberOfOccurrences(T valueToEvaluate) {
51
+        return null;
52
+    }
7 53
 }

+ 2
- 2
src/test/java/com/zipcodewilmington/arrayutility/GetMostCommonFromMergeTest.java Просмотреть файл

@@ -7,7 +7,7 @@ import org.junit.Test;
7 7
  * Created by leon on 3/1/18.
8 8
  * The purpose of this class is to thoroughly test the method getMostCommonFromMerge()
9 9
  */
10
-public class GetMostCommonFromMergeTest {
10
+public class GetMostCommonFromMergeTest <T> {
11 11
     @Test
12 12
     public void integerTest() {
13 13
         // Given
@@ -69,4 +69,4 @@ public class GetMostCommonFromMergeTest {
69 69
         // Then
70 70
         Assert.assertEquals(expected, actual);
71 71
     }
72
-}
72
+}

+ 0
- 1
src/test/java/com/zipcodewilmington/arrayutility/RemoveValueTest.java Просмотреть файл

@@ -1,6 +1,5 @@
1 1
 package com.zipcodewilmington.arrayutility;
2 2
 
3
-import com.zipcodewilmington.UnitTestingUtils;
4 3
 import org.junit.Test;
5 4
 
6 5
 /**