-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathStringDuplicateDeleter.java
More file actions
58 lines (45 loc) · 1.71 KB
/
StringDuplicateDeleter.java
File metadata and controls
58 lines (45 loc) · 1.71 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
package com.zipcodewilmington.looplabs;
import java.lang.reflect.Array;
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[] removeDuplicates(int maxNumberOfDuplications) {
String[] removeDupExact = new String[0];
for (int i =0; i < this.array.length; i++){
if (getNumberOfOccurrences(this.array,this.array[i]) < maxNumberOfDuplications){
int element = removeDupExact.length;
removeDupExact = Arrays.copyOf(removeDupExact,removeDupExact.length +1);
removeDupExact[element] = this.array[i];
}
}
return removeDupExact;
}
@Override
public String[] removeDuplicatesExactly(int exactNumberOfDuplications) {
String[] removeDupExact = new String[0];
for (int i =0; i < this.array.length; i++){
if (getNumberOfOccurrences(this.array,this.array[i])!= exactNumberOfDuplications){
int element = removeDupExact.length;
removeDupExact = Arrays.copyOf(removeDupExact,removeDupExact.length +1);
removeDupExact[element] = this.array[i];
}
}
return removeDupExact;
}
public int getNumberOfOccurrences (String[]array,String value) {
int counter = 0;
for (int i = 0; i < array.length; i++) {
if (array[i].equals(value)) {
counter++;
}
}
return counter;
}
}