Selaa lähdekoodia

Remove value tests passed

Lauren Green 6 vuotta sitten
vanhempi
commit
ad407ae25f

+ 40
- 1
src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java Näytä tiedosto

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

+ 0
- 1
src/test/java/com/zipcodewilmington/arrayutility/RemoveValueTest.java Näytä tiedosto

@@ -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
 /**