|
@@ -1,8 +1,61 @@
|
1
|
1
|
package com.zipcodewilmington.looplabs;
|
2
|
2
|
|
|
3
|
+import java.util.Arrays;
|
|
4
|
+
|
3
|
5
|
/**
|
4
|
6
|
* Created by leon on 1/28/18.
|
5
|
7
|
* @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
|
6
|
8
|
*/
|
7
|
9
|
public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
|
|
10
|
+
|
|
11
|
+ public StringDuplicateDeleter(String[] intArray) {
|
|
12
|
+ super(intArray);
|
|
13
|
+ }
|
|
14
|
+
|
|
15
|
+ @Override
|
|
16
|
+ public String[] removeDuplicates(int maxNumberOfDuplications) {
|
|
17
|
+ Integer[] dupeCounts = countDupes();
|
|
18
|
+ String[] noXDupes = new String[this.array.length];
|
|
19
|
+ int index = 0;
|
|
20
|
+
|
|
21
|
+ for (int i = 0; i < dupeCounts.length; i++) {
|
|
22
|
+ if (dupeCounts[i] < maxNumberOfDuplications) {
|
|
23
|
+ noXDupes[index] = array[i];
|
|
24
|
+ index++;
|
|
25
|
+ }
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+ return Arrays.copyOfRange(noXDupes, 0, index);
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ @Override
|
|
32
|
+ public String[] removeDuplicatesExactly(int exactNumberOfDuplications) {
|
|
33
|
+ Integer[] dupeCounts = countDupes();
|
|
34
|
+ String[] noXDupes = new String[this.array.length];
|
|
35
|
+ int index = 0;
|
|
36
|
+
|
|
37
|
+ for (int i = 0; i < dupeCounts.length; i++) {
|
|
38
|
+ if (dupeCounts[i] != exactNumberOfDuplications) {
|
|
39
|
+ noXDupes[index] = array[i];
|
|
40
|
+ index++;
|
|
41
|
+ }
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ return Arrays.copyOfRange(noXDupes, 0, index);
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ public Integer[] countDupes() {
|
|
48
|
+ Integer[] dupeCount = new Integer[array.length];
|
|
49
|
+ Arrays.fill(dupeCount, 0);
|
|
50
|
+
|
|
51
|
+ for (int i = 0; i < array.length; i++) {
|
|
52
|
+ for (int j = 0; j < array.length; j++) {
|
|
53
|
+ if (array[i].equals(array[j])) {
|
|
54
|
+ dupeCount[i]++;
|
|
55
|
+ }
|
|
56
|
+ }
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ return dupeCount;
|
|
60
|
+ }
|
8
|
61
|
}
|