-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathArrayUtility.java
More file actions
65 lines (56 loc) · 1.69 KB
/
ArrayUtility.java
File metadata and controls
65 lines (56 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.zipcodewilmington.arrayutility;
import org.omg.CORBA.Object;
import java.util.Arrays;
/**
* Created by leon on 3/6/18.
*/
public class ArrayUtility<T> {
T[] inputArray;
public ArrayUtility(T[] array){
this.inputArray = array;
}
public Integer countDuplicatesInMerge(T[] arrayToMerge, T valueToEvaluate) {
Integer counter = getNumberOfOccurrences(valueToEvaluate);
for(T t: arrayToMerge){
if(t == valueToEvaluate){ counter++; }
} return counter;
}
public T getMostCommonFromMerge(T[] arrayToMerge) {
T mostOccuring = null, temp;
int counter = 0, holder = 0;
for(int i = 0; i < arrayToMerge.length; i++ ){
temp = arrayToMerge[i];
for(int j = 0; j < arrayToMerge.length; j++){
if(temp.equals(arrayToMerge[j])){
counter++;
}
}
if(counter > holder){
holder = counter;
mostOccuring = arrayToMerge[i];
}
counter = 0;
}
return mostOccuring;
}
public Integer getNumberOfOccurrences(T valueToEvaluate) {
Integer counter = 0;
for(T t: inputArray){
if(t == valueToEvaluate){
counter++;
}
}
return counter;
}
public T[] removeValue(T valueToRemove) {
Integer occurs = inputArray.length - getNumberOfOccurrences(valueToRemove);
T[] newT = Arrays.copyOf(inputArray,occurs);
int j = 0;
for(T t: inputArray){
if(t != valueToRemove){
newT[j] = t;
j++;
}
} return newT;
}
}