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