Khalil Malik Saboor před 6 roky
rodič
revize
4205cc2576

+ 63
- 1
src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java Zobrazit soubor

@@ -3,5 +3,67 @@ package com.zipcodewilmington.arrayutility;
3 3
 /**
4 4
  * Created by leon on 3/6/18.
5 5
  */
6
-public class ArrayUtility {
6
+public class ArrayUtility <T> {
7
+    private T[] inputArray;
8
+
9
+    ArrayUtility(T[] inputArray){
10
+        this.inputArray = inputArray;
11
+    }
12
+
13
+    public Integer countDuplicatesInMerge(T [] arrayToMerge, T valueToEvaluate) {
14
+        Integer count = 0;
15
+        T[] newArray = merge(inputArray,arrayToMerge);
16
+
17
+        for (int i = 0; i < newArray.length ;i++) {
18
+            if (newArray[i] == valueToEvaluate){
19
+                count++;
20
+            }
21
+        }
22
+        return count;
23
+
24
+    }
25
+    public T getMostCommonFromMerge(T[] arrayToMerge) {
26
+        Object[] newArray = merge(inputArray,arrayToMerge);
27
+        T mostCommonValue = (T) newArray[0];
28
+        Object temp;
29
+        int count = 1, tempCount;
30
+        int i;
31
+        int j;
32
+        for (i = 0; i <newArray.length-1 ; i++) {
33
+            temp = newArray[i];
34
+            tempCount = 0;
35
+            for (j = 0; j <newArray.length ; j++) {
36
+                if (temp == newArray[j])
37
+                tempCount++;
38
+            }
39
+            if (tempCount > count)
40
+            {
41
+                mostCommonValue = (T) temp;
42
+                count = tempCount;
43
+            }
44
+        }
45
+        return mostCommonValue;
46
+    }
47
+
48
+    public Integer getNumberOfOccurrences(T valueToEvaluate) {
49
+        Integer count = 0;
50
+        for (int i = 0; i < inputArray.length ;i++) {
51
+            if (inputArray[i] == valueToEvaluate){
52
+                count++;
53
+            }
54
+        }
55
+        return count;
56
+
57
+    }
58
+
59
+    public T[] removeValue(T valueToRemove) {
60
+        return null;
61
+
62
+    }
63
+    public T[] merge(T[] inputArray, T[] arrayToMerge){
64
+        T[] newArr = (T[]) new Object[arrayToMerge.length + inputArray.length];
65
+        System.arraycopy(inputArray,0,newArr,0,inputArray.length);
66
+        System.arraycopy(arrayToMerge,0,newArr,inputArray.length,arrayToMerge.length);
67
+        return newArr;
68
+    }
7 69
 }

+ 3
- 0
src/test/java/com/zipcodewilmington/arrayutility/CountDuplicatesInMergeTest.java Zobrazit soubor

@@ -7,6 +7,9 @@ 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 countDuplicatesInMerge()
9 9
  */
10
+
11
+//mergeArray
12
+//contains two arraycopy
10 13
 public class CountDuplicatesInMergeTest {
11 14
     @Test
12 15
     public void integerTest() {

+ 1
- 1
src/test/java/com/zipcodewilmington/arrayutility/RemoveValueTest.java Zobrazit soubor

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