|
@@ -2,5 +2,85 @@
|
2
|
2
|
|
3
|
3
|
|
4
|
4
|
public class IntegerDuplicateDeleter extends DuplicateDeleter<Integer>{
|
|
5
|
+
|
|
6
|
+ public IntegerDuplicateDeleter(Integer[] array) {
|
|
7
|
+ super(array);
|
|
8
|
+ }
|
|
9
|
+
|
|
10
|
+ public Integer[] removeDuplicates(int maxNumberOfDuplications) {
|
|
11
|
+ StringBuilder sb = new StringBuilder();
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+ for (int i = 0; i < array.length; i++) {
|
|
16
|
+
|
|
17
|
+ if(getCount(array[i]) < maxNumberOfDuplications){
|
|
18
|
+
|
|
19
|
+ sb.append((array[i]) + " ");
|
|
20
|
+ }
|
|
21
|
+ }
|
|
22
|
+ String arrString = sb.toString();
|
|
23
|
+ String [] arrPlus = arrString.split(" ");
|
|
24
|
+ Integer[] newArr = new Integer[arrPlus.length];
|
|
25
|
+
|
|
26
|
+ for (int i = 0; i < newArr.length; i++) {
|
|
27
|
+ try {newArr[i] = Integer.parseInt(arrPlus[i]);}
|
|
28
|
+ catch (NumberFormatException e){}
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ Integer[] empty = new Integer[]{};
|
|
32
|
+
|
|
33
|
+ if (newArr.length == 1 && newArr[0] == null) {
|
|
34
|
+ return empty;
|
|
35
|
+ } else { return newArr;}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) {
|
|
41
|
+ StringBuilder sb = new StringBuilder();
|
|
42
|
+
|
|
43
|
+ String tester = array.toString();
|
|
44
|
+
|
|
45
|
+ for (int i = 0; i < array.length; i++) {
|
|
46
|
+
|
|
47
|
+ if(getCount(array[i]) < exactNumberOfDuplications || getCount(array[i])
|
|
48
|
+ > exactNumberOfDuplications) {
|
|
49
|
+
|
|
50
|
+ sb.append((array[i]) + " ");
|
|
51
|
+ }
|
|
52
|
+ }
|
|
53
|
+ String arrString = sb.toString();
|
|
54
|
+ String [] arrPlus = arrString.split(" ");
|
|
55
|
+ Integer[] newArr = new Integer[arrPlus.length];
|
|
56
|
+
|
|
57
|
+ for (int i = 0; i < newArr.length; i++) {
|
|
58
|
+ try {newArr[i] = Integer.parseInt(arrPlus[i]);}
|
|
59
|
+ catch (NumberFormatException e){}
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ Integer[] empty = new Integer[]{};
|
|
63
|
+
|
|
64
|
+ if (newArr.length == 1 && newArr[0] == null) {
|
|
65
|
+ return empty;
|
|
66
|
+ } else { return newArr;}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+ }
|
5
|
70
|
|
|
71
|
+
|
|
72
|
+ private int getCount (Integer value){
|
|
73
|
+ int count = 0;
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+ for (Integer e : array){
|
|
77
|
+
|
|
78
|
+ if (e == value) {
|
|
79
|
+
|
|
80
|
+ count++;
|
|
81
|
+
|
|
82
|
+ }
|
|
83
|
+ }
|
|
84
|
+ return count;
|
|
85
|
+ }
|
6
|
86
|
}
|