|
@@ -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
|
}
|