#10 mrdimarino

Open
mdimarino wants to merge 1 commits from mdimarino/CR-MesoLabs-OOP-DuplicateDeleter:master into master

+ 59
- 0
src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java View File

@@ -1,8 +1,67 @@
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> {
11
+
12
+    public IntegerDuplicateDeleter(Integer[] array){
13
+        super(array);
14
+    }
15
+
16
+    @Override
17
+    public Integer[] removeDuplicates(int maxNumberOfDuplications) {
18
+        Integer[] newArray = new Integer[array.length];
19
+        int counter = 0;
20
+        int index = 0;
21
+        int newLength = 0;
22
+        for (int i = 0; i < array.length; i++){
23
+            for(int j = 0; j < array.length; j++) {
24
+                if (array[i].equals(array[j])) {
25
+                    counter++;
26
+                }
27
+            }
28
+
29
+            if (counter < maxNumberOfDuplications){
30
+                newArray[index] = array[i];
31
+                index++;
32
+                newLength++;
33
+
34
+            }
35
+            counter= 0;
36
+        }
37
+        return Arrays.copyOfRange(newArray, 0, newLength);
38
+    }
39
+
40
+    @Override
41
+    public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) {
42
+        Integer[] newArray = new Integer[array.length];
43
+        int counter = 0;
44
+        int index = 0;
45
+        int newLength = 0;
46
+        for (int i = 0; i < array.length; i++){
47
+            for(int j = 0; j < array.length; j++) {
48
+                if (array[i].equals(array[j])) {
49
+                    counter++;
50
+                }
51
+            }
52
+
53
+            if (counter != exactNumberOfDuplications){
54
+                newArray[index] = array[i];
55
+                index++;
56
+                newLength++;
57
+
58
+            }
59
+
60
+            counter = 0;
61
+
62
+        }
63
+        return Arrays.copyOfRange(newArray, 0, newLength);
64
+    }
65
+
66
+
8 67
 }

+ 57
- 0
src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java View File

@@ -1,8 +1,65 @@
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[] array){
12
+        super(array);
13
+    }
14
+    @Override
15
+
16
+    public String[] removeDuplicates(int maxNumberOfDuplications) {
17
+        String[] newArray = new String[array.length];
18
+        int counter = 0;
19
+        int index = 0;
20
+        int newLength = 0;
21
+        for (int i = 0; i < array.length; i++){
22
+            for(int j = 0; j < array.length; j++) {
23
+                if (array[i].equals(array[j])) {
24
+                    counter++;
25
+                }
26
+            }
27
+
28
+            if (counter < maxNumberOfDuplications){
29
+                newArray[index] = array[i];
30
+                index++;
31
+                newLength++;
32
+
33
+            }
34
+            counter= 0;
35
+        }
36
+        return Arrays.copyOfRange(newArray, 0, newLength);
37
+    }
38
+
39
+    @Override
40
+    public String[] removeDuplicatesExactly(int exactNumberOfDuplications) {
41
+        String[] newArray = new String[array.length];
42
+        int counter = 0;
43
+        int index = 0;
44
+        int newLength = 0;
45
+        for (int i = 0; i < array.length; i++){
46
+            for(int j = 0; j < array.length; j++) {
47
+                if (array[i].equals(array[j])) {
48
+                    counter++;
49
+                }
50
+            }
51
+
52
+            if (counter != exactNumberOfDuplications){
53
+                newArray[index] = array[i];
54
+                index++;
55
+                newLength++;
56
+
57
+            }
58
+
59
+            counter = 0;
60
+
61
+        }
62
+        return Arrays.copyOfRange(newArray, 0, newLength);
63
+
64
+    }
8 65
 }

+ 0
- 25
src/test/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleterTest.java View File

@@ -64,25 +64,6 @@ public class IntegerDuplicateDeleterTest {
64 64
 
65 65
 
66 66
 
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86 67
     @Test
87 68
     public void testRemoveDuplicates0() {
88 69
         Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
@@ -140,12 +121,6 @@ public class IntegerDuplicateDeleterTest {
140 121
 
141 122
 
142 123
 
143
-
144
-
145
-
146
-
147
-
148
-
149 124
     @Test
150 125
     public void testRemoveDuplicatesExactlyIdempotence() {
151 126
         Integer[] input = RandomNumberFactory.createIntegers(0,50,150);