Shivam Patel 6 年 前
コミット
6cd45dc7a6

+ 85
- 1
src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java ファイルの表示

@@ -1,7 +1,91 @@
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<shivam> {
10
+
11
+    private shivam[] inputArray;
12
+
13
+    public ArrayUtility(shivam[] inputArray) {
14
+
15
+        this.inputArray = inputArray;
16
+
17
+    }
18
+
19
+    public shivam[] merge(shivam[] inputArray, shivam[] arrayToMerge) {
20
+        shivam[] newArr = (shivam[]) new Object[arrayToMerge.length + inputArray.length];
21
+        System.arraycopy(inputArray, 0, newArr, 0, inputArray.length);
22
+        System.arraycopy(arrayToMerge, 0, newArr, inputArray.length, arrayToMerge.length);
23
+
24
+        return newArr;
25
+    }
26
+
27
+    public Integer countDuplicatesInMerge(shivam[] arrayToMerge, shivam valueToEvaluate) {
28
+        int count = 0;
29
+        shivam[] newArr = merge(arrayToMerge, inputArray);
30
+
31
+        for (shivam s : newArr) {
32
+            if (s.equals(valueToEvaluate)) {
33
+
34
+                count++;
35
+            }
36
+
37
+        }
38
+        return count;
39
+    }
40
+
41
+    public shivam getMostCommonFromMerge(shivam[] arrayToMerge) {
42
+        shivam[] newArr = merge(inputArray, arrayToMerge);
43
+        shivam common = newArr[0];
44
+        int count = 1;
45
+        shivam temp;
46
+        int tempCount = 0;
47
+
48
+        for (int i = 0; i < (newArr.length - 1); i++) {
49
+            temp = newArr[i];
50
+
51
+            for (int j = 1; j < newArr.length; j++) {
52
+                if (temp == newArr[j])
53
+                    tempCount++;
54
+            }
55
+            if (tempCount > count) {
56
+                common = temp;
57
+                count = tempCount;
58
+            }
59
+        }
60
+
61
+        return common;
62
+    }
63
+
64
+    public Integer getNumberOfOccurrences(shivam valueToEvaluate) {
65
+        int count = 0;
66
+
67
+        for (shivam s : inputArray) {
68
+            if (s.equals(valueToEvaluate)) {
69
+                count++;
70
+
71
+            }
72
+        }
73
+
74
+        return count;
75
+    }
76
+
77
+    public shivam[] removeValue(shivam valueToRemove) {
78
+        Integer removed = getNumberOfOccurrences(valueToRemove);
79
+        shivam[] array = (shivam[]) Array.newInstance(inputArray.getClass().getComponentType(), inputArray.length-removed);
80
+        int count = 0;
81
+        for (int i = 0; i < inputArray.length; i++) {
82
+            if (!inputArray[i].equals(valueToRemove)) {
83
+                array[count] = inputArray[i];
84
+                count++;
85
+
86
+            }
87
+
88
+        }
89
+        return array;
90
+    }
7 91
 }

+ 5
- 4
src/test/java/com/zipcodewilmington/arrayutility/GetMostCommonFromMergeTest.java ファイルの表示

@@ -3,10 +3,11 @@ package com.zipcodewilmington.arrayutility;
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6
-/**
7
- * Created by leon on 3/1/18.
8
- * The purpose of this class is to thoroughly test the method getMostCommonFromMerge()
9
- */
6
+//*
7
+ //* Created by leon on 3/1/18.
8
+ //* The purpose of this class is to thoroughly test the method getMostCommonFromMerge()
9
+
10
+
10 11
 public class GetMostCommonFromMergeTest {
11 12
     @Test
12 13
     public void integerTest() {

+ 5
- 4
src/test/java/com/zipcodewilmington/arrayutility/GetNumberOfOccurrencesTest.java ファイルの表示

@@ -3,10 +3,11 @@ package com.zipcodewilmington.arrayutility;
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6
-/**
7
- * Created by leon on 3/1/18.
8
- * The purpose of this class is to thoroughly test the method getNumberOfOccurrences()
9
- */
6
+//*
7
+ //* Created by leon on 3/1/18.
8
+ //* The purpose of this class is to thoroughly test the method getNumberOfOccurrences()
9
+
10
+
10 11
 public class GetNumberOfOccurrencesTest {
11 12
     @Test
12 13
     public void integerTest() {

+ 2
- 5
src/test/java/com/zipcodewilmington/arrayutility/RemoveValueTest.java ファイルの表示

@@ -1,12 +1,9 @@
1 1
 package com.zipcodewilmington.arrayutility;
2 2
 
3
-import com.zipcodewilmington.UnitTestingUtils;
4 3
 import org.junit.Test;
5 4
 
6
-/**
7
- * Created by leon on 3/1/18.
8
- * The purpose of this class is to thoroughly test the method removeValue()
9
- */
5
+
6
+
10 7
 public class RemoveValueTest {
11 8
     @Test
12 9
     public void integerTest() {