-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathStringDuplicateDeleter.java
More file actions
72 lines (45 loc) · 1.78 KB
/
StringDuplicateDeleter.java
File metadata and controls
72 lines (45 loc) · 1.78 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
66
67
68
69
70
71
72
package com.zipcodewilmington.looplabs;
import java.util.Arrays;
/**
* Created by leon on 1/28/18.
*
* @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
*/
public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
public StringDuplicateDeleter(String[] intArray) {
super(intArray);
}
@Override
public String[] removeDuplicatesExactly(int exactNumberOfDuplications) {
String[] noStringDupsArray = new String[0];
for (int i = 0; i < this.array.length; i++) {
if (getNumberOfOccurrences(this.array, this.array[i]) != exactNumberOfDuplications) {
int stringElements = noStringDupsArray.length;
noStringDupsArray = Arrays.copyOf(noStringDupsArray, noStringDupsArray.length + 1);
noStringDupsArray[stringElements] = this.array[i];
}
}
return noStringDupsArray;
}
public static int getNumberOfOccurrences(String[] inputArray, String value) {
int valueCounter = 0;
for (String arrayElement : inputArray) {
if (arrayElement.equalsIgnoreCase(value)) {
valueCounter++;
}
}
return valueCounter;
}
@Override
public String[] removeDuplicates(int maxNumberOfDuplications) {
String[] maxDupsArray = new String[0];
for (int i = 0; i < this.array.length; i++) {
if (getNumberOfOccurrences(this.array, this.array[i]) < maxNumberOfDuplications) {
int arrayElements = maxDupsArray.length;
maxDupsArray = Arrays.copyOf(maxDupsArray, maxDupsArray.length + 1);
maxDupsArray[arrayElements] = this.array[i];
}
}
return maxDupsArray;
}
}