#15 lab done

오픈
Soujanya Soujanya/CR-MesoLabs-OOP-DuplicateDeleter:master 에서 master 로 1 commits 를 머지하려 합니다

+ 2
- 1
src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleter.java 파일 보기

@@ -6,7 +6,8 @@ package com.zipcodewilmington.looplabs;
6 6
 public abstract class DuplicateDeleter<T> implements DuplicateDeleterInterface<T> {
7 7
     protected T[] array;
8 8
 
9
-    public DuplicateDeleter(T[] intArray) {
9
+    public DuplicateDeleter(T[] intArray)
10
+    {
10 11
         this.array = intArray;
11 12
     }
12 13
 

+ 113
- 0
src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java 파일 보기

@@ -1,8 +1,121 @@
1 1
 package com.zipcodewilmington.looplabs;
2 2
 
3
+import java.util.*;
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
+    ArrayList<Integer> list = new ArrayList<Integer>();
11
+
12
+    public IntegerDuplicateDeleter(Integer[] intArray) {
13
+        super(intArray);
14
+    }
15
+
16
+    @Override
17
+    public Integer[] removeDuplicates(int maxNumberOfDuplications) {
18
+        Arrays.sort (array);
19
+        int n = array.length;
20
+        int count = 0;
21
+        int num=0;
22
+        ArrayList<Integer>arraylist=new ArrayList<>() ;
23
+        //Get all unique values
24
+        HashSet set = new HashSet();
25
+        for (int i=0; i < array.length;i++) {
26
+            set.add(new Integer(array[i]));
27
+        }
28
+
29
+        Map<Integer,Integer> map=new HashMap<>();
30
+        Iterator it = set.iterator();
31
+        // Loop through the set for duplicates count and add it to Map
32
+        Integer temp;
33
+        while (it.hasNext()) {
34
+            //initialize the counter to 0
35
+            count = 0;
36
+            temp = (Integer) it.next();
37
+
38
+            //loop through the array sorted to count the duplicates
39
+
40
+            for (int j = 0; j < n; j++) {
41
+
42
+                if (temp.intValue() == array[j]) {
43
+
44
+                    count++;
45
+
46
+
47
+                }
48
+
49
+            }
50
+
51
+            map.put(temp, count);
52
+        }
53
+
54
+        for(Map.Entry<Integer,Integer>entry: map.entrySet()){
55
+            if(entry.getValue().intValue() < maxNumberOfDuplications ){
56
+                for (int i=0;  i< entry.getValue().intValue(); i++)
57
+                    arraylist.add(entry.getKey() );
58
+
59
+            }
60
+
61
+        }
62
+        Integer[] integers =arraylist.toArray(new  Integer[arraylist.size() ] ) ;     //return new Integer[0];
63
+
64
+        return  integers ;
65
+
66
+
67
+    }
68
+
69
+    @Override
70
+    public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) {
71
+        Arrays.sort (array);
72
+        int n = array.length;
73
+        int count = 0;
74
+        int num=0;
75
+        ArrayList<Integer>arraylist=new ArrayList<>() ;
76
+        //Get all unique values
77
+        HashSet set = new HashSet();
78
+        for (int i=0; i < array.length;i++) {
79
+            set.add(new Integer(array[i]));
80
+        }
81
+
82
+        Map<Integer,Integer>map=new HashMap<>();
83
+        Iterator it = set.iterator();
84
+        // Loop through the set for duplicates count and add it to Map
85
+        Integer temp;
86
+        while (it.hasNext()) {
87
+            //initialize the counter to 0
88
+            count = 0;
89
+            temp = (Integer) it.next();
90
+
91
+            //loop through the array sorted to count the duplicates
92
+
93
+            for (int j = 0; j < n; j++) {
94
+
95
+                if (temp.intValue() == array[j]) {
96
+
97
+                    count++;
98
+
99
+
100
+                }
101
+
102
+            }
103
+
104
+            map.put(temp, count);
105
+        }
106
+
107
+        for(Map.Entry<Integer,Integer>entry: map.entrySet()){
108
+            if(entry.getValue().intValue() != exactNumberOfDuplications){
109
+                for (int i=0;  i< entry.getValue().intValue(); i++)
110
+                    arraylist.add(entry.getKey() );
111
+
112
+            }
113
+
114
+        }
115
+        Integer[] integers =arraylist.toArray(new  Integer[arraylist.size() ] ) ;     //return new Integer[0];
116
+
117
+        return  integers ;
118
+    }
119
+
120
+
8 121
 }

+ 91
- 1
src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java 파일 보기

@@ -1,8 +1,98 @@
1 1
 package com.zipcodewilmington.looplabs;
2 2
 
3
+import java.util.*;
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
-public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
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
+        Arrays.sort(array);
18
+        int n = array.length;
19
+        int count;
20
+        ArrayList<String>list=new ArrayList<>() ;
21
+        Map<String,Integer > map=new HashMap<>();
22
+        Set<String> set = new HashSet<String>();
23
+        for (int i = 0; i < n; i++) {
24
+            set.add(array[i]);
25
+        }
26
+        Iterator<String> itr = set.iterator();
27
+        String temp;
28
+        while (itr.hasNext()) {
29
+            count = 0;
30
+            temp =  itr.next();
31
+            for (int j = 0; j < n; j++) {
32
+
33
+                if (temp == array[j]) {
34
+
35
+                    count++;
36
+                }
37
+
38
+
39
+            }
40
+            map.put(temp,count);
41
+
42
+        }
43
+        for(Map.Entry<String,Integer>entry :map.entrySet() ){
44
+            if(entry.getValue().intValue()<maxNumberOfDuplications){
45
+                // for (int i=0;  i< entry.getValue().intValue(); i++)
46
+                list.add(entry.getKey() );
47
+
48
+
49
+            }
50
+        }
51
+        String[] str=list.toArray(new String[list.size() ]);
52
+
53
+
54
+        return str;
55
+    }
56
+
57
+    @Override
58
+    public String[] removeDuplicatesExactly(int exactNumberOfDuplications) {
59
+
60
+        Arrays.sort(array);
61
+        int n = array.length;
62
+        int count;
63
+        ArrayList<String> list=new ArrayList<>() ;
64
+        Map<String,Integer > map=new HashMap<>();
65
+        Set<String> set = new HashSet<String>();
66
+        for (int i = 0; i < n; i++) {
67
+            set.add(array[i]);
68
+        }
69
+        Iterator<String> itr = set.iterator();
70
+        String temp;
71
+        while (itr.hasNext()) {
72
+            count = 0;
73
+            temp =  itr.next();
74
+            for (int j = 0; j < n; j++) {
75
+
76
+                if (temp == array[j]) {
77
+
78
+                    count++;
79
+                }
80
+
81
+
82
+            }
83
+            map.put(temp,count);
84
+
85
+        }
86
+        for(Map.Entry<String,Integer>entry :map.entrySet() ){
87
+            if(entry.getValue().intValue() != exactNumberOfDuplications){
88
+                for (int i=0;  i< entry.getValue().intValue(); i++)
89
+                    list.add(entry.getKey() );
90
+
91
+
92
+            }
93
+        }
94
+        String[] str=list.toArray(new String[list.size() ]);
95
+
96
+        return str;
97
+    }
8 98
 }

+ 0
- 26
src/test/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleterTest.java 파일 보기

@@ -57,32 +57,6 @@ public class IntegerDuplicateDeleterTest {
57 57
         TestUtils.assertArrayEquality(expected, actual);
58 58
     }
59 59
 
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86 60
     @Test
87 61
     public void testRemoveDuplicates0() {
88 62
         Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};