|
@@ -1,7 +1,46 @@
|
1
|
1
|
package com.zipcodewilmington.arrayutility;
|
2
|
2
|
|
|
3
|
+import java.lang.reflect.Array;
|
|
4
|
+import java.util.Arrays;
|
|
5
|
+import java.util.HashSet;
|
|
6
|
+import java.util.Map;
|
|
7
|
+import java.util.Set;
|
|
8
|
+import java.util.stream.Collectors;
|
|
9
|
+import java.util.stream.Stream;
|
|
10
|
+
|
3
|
11
|
/**
|
4
|
12
|
* Created by leon on 3/6/18.
|
5
|
13
|
*/
|
6
|
|
-public class ArrayUtility {
|
|
14
|
+public class ArrayUtility<T> {
|
|
15
|
+
|
|
16
|
+ private T[] element;
|
|
17
|
+
|
|
18
|
+ public ArrayUtility( T[] array){
|
|
19
|
+ this.element = array;
|
|
20
|
+ }
|
|
21
|
+
|
|
22
|
+ public Integer countDuplicatesInMerge(T[] arrayToMerge, T valueToEvaluate) {
|
|
23
|
+ T[] merged = Stream.concat(Arrays.stream(arrayToMerge), Arrays.stream(element))
|
|
24
|
+ .toArray(size -> (T[]) Array.newInstance(element.getClass().getComponentType(), element.length + arrayToMerge.length));
|
|
25
|
+
|
|
26
|
+ Integer count = 0;
|
|
27
|
+ for (T element: merged){
|
|
28
|
+ if(element.equals(valueToEvaluate)){
|
|
29
|
+ count++;
|
|
30
|
+ }
|
|
31
|
+ }
|
|
32
|
+ return count;
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ public T[] removeValue(T valueToRemove) {
|
|
36
|
+ return null;
|
|
37
|
+ }
|
|
38
|
+
|
|
39
|
+ public T getMostCommonFromMerge(T[] arrayToMerge) {
|
|
40
|
+ return null;
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ public Integer getNumberOfOccurrences(T valueToEvaluate) {
|
|
44
|
+ return null;
|
|
45
|
+ }
|
7
|
46
|
}
|