nafis nibir преди 6 години
родител
ревизия
666be9991e

+ 40
- 1
src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java Целия файл

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

+ 1
- 0
src/test/java/com/zipcodewilmington/arrayutility/CountDuplicatesInMergeTest.java Целия файл

@@ -10,6 +10,7 @@ import org.junit.Test;
10 10
 public class CountDuplicatesInMergeTest {
11 11
     @Test
12 12
     public void integerTest() {
13
+
13 14
         // Given
14 15
         Integer valueToEvaluate = 7;
15 16
         Integer expected = 5;

+ 0
- 2
src/test/java/com/zipcodewilmington/arrayutility/RemoveValueTest.java Целия файл

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