|
@@ -1,8 +1,51 @@
|
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
|
+ String[] stringArr = new String[array.length];
|
|
18
|
+ int c = 0;
|
|
19
|
+ for (String anArray : array) {
|
|
20
|
+ if (countDupes(anArray) < maxNumberOfDuplications) {
|
|
21
|
+ stringArr[c] = anArray;
|
|
22
|
+ c++;
|
|
23
|
+ }
|
|
24
|
+ }
|
|
25
|
+ return Arrays.copyOfRange(stringArr,0, c);
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+ @Override
|
|
30
|
+ public String[] removeDuplicatesExactly(int exactNumberOfDuplications) {
|
|
31
|
+
|
|
32
|
+ String[] stringArr = new String[array.length];
|
|
33
|
+ int c = 0;
|
|
34
|
+ for (String anArray : array) {
|
|
35
|
+ if (countDupes(anArray) != exactNumberOfDuplications) {
|
|
36
|
+ stringArr[c] = anArray;
|
|
37
|
+ c++;
|
|
38
|
+ }
|
|
39
|
+ }
|
|
40
|
+ return Arrays.copyOfRange(stringArr,0, c); }
|
|
41
|
+
|
|
42
|
+ private int countDupes(String str){
|
|
43
|
+ int c = 0;
|
|
44
|
+ for (String index : array){
|
|
45
|
+ if(index.equals(str)){
|
|
46
|
+ c++;
|
|
47
|
+ }
|
|
48
|
+ }
|
|
49
|
+ return c;
|
|
50
|
+ }
|
8
|
51
|
}
|