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