소스 검색

figured it out better late than never

Chad 6 년 전
부모
커밋
38b0cc2b12
3개의 변경된 파일162개의 추가작업 그리고 74개의 파일을 삭제
  1. 72
    2
      IntegerDuplicateDeleter.java
  2. 46
    1
      StringDuplicateDeleter.java
  3. 44
    71
      package.bluej

+ 72
- 2
IntegerDuplicateDeleter.java 파일 보기

@@ -1,6 +1,76 @@
1
- 
2
-
3 1
 
4 2
 public class IntegerDuplicateDeleter extends DuplicateDeleter<Integer>{
3
+    public IntegerDuplicateDeleter(Integer[] array){
4
+        super(array);
5
+    }
6
+
7
+    public Integer[] removeDuplicates(int maxNumberOfDuplications){
8
+        StringBuilder remover = new StringBuilder();
9
+        for(int i=0; i<array.length; i++){
10
+            if(countDuplicates(i)<maxNumberOfDuplications){
11
+                remover.append(array[i]+" ");
12
+            }
13
+        }
14
+        String[] parts = remover.toString().split(" ");
15
+        Integer[] removed;
16
+        if(parts[0].equals("")){
17
+            removed= new Integer[]{};
18
+        }else{
19
+            removed = new Integer[parts.length];
20
+            for(int i=0; i<parts.length; i++){
21
+                removed[i] = Integer.parseInt(parts[i]);
22
+            }
23
+        }
24
+        return removed;
25
+    }
26
+
27
+    public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications){
28
+        StringBuilder remover = new StringBuilder();
29
+        for(int i=0; i<array.length; i++){
30
+            if(countDuplicates(i) != exactNumberOfDuplications){
31
+                remover.append(array[i]+" ");
32
+            }
33
+        }
34
+        String[] parts = remover.toString().split(" ");
35
+        Integer[] removed;
36
+        if(parts[0].equals("")){
37
+            removed= new Integer[]{};
38
+        }else{
39
+            removed = new Integer[parts.length];
40
+            for(int i=0; i<parts.length; i++){
41
+                removed[i] = Integer.parseInt(parts[i]);
42
+            }
43
+        }
44
+        return removed;
45
+    }
46
+
47
+    public int countDuplicates(int i){
48
+        int dupes = 0;
49
+        for(int j=0; j<array.length; j++){
50
+            if(array[i] == array[j]){
51
+                dupes++;
52
+            }
53
+        }
54
+        return dupes;
55
+    }   
5 56
 
57
+    // public String dupesString(int maxNumberOfDuplications){
58
+    // StringBuilder dupes = new StringBuilder();
59
+    // boolean skip = false;
60
+    // int totalDupes=0;
61
+    // for(int i=0; i<array.length; i++){
62
+    // for(int j=0; j<dupes.length(); j++){
63
+    // if (array[i].toString().equals(dupes.substring(j,j+1))){
64
+    // skip = true;
65
+    // }
66
+    // }
67
+    // if(countDuplicates(i)>=maxNumberOfDuplications && skip == false){
68
+    // dupes.append(array[i].toString());
69
+    // totalDupes += countDuplicates(i);
70
+    // }
71
+    // skip = false;
72
+    // }
73
+    // dupes.append(totalDupes);
74
+    // return dupes.toString();
75
+    // }
6 76
 }

+ 46
- 1
StringDuplicateDeleter.java 파일 보기

@@ -1,6 +1,51 @@
1
- 
2 1
 
3 2
 public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
3
+    public StringDuplicateDeleter(String[] array){
4
+        super(array);
5
+    }
4 6
 
7
+    public String[] removeDuplicates(int maxNumberOfDuplications){
8
+        StringBuilder remover = new StringBuilder();
9
+        for(int i=0; i<array.length; i++){
10
+            if(countDuplicates(i) < maxNumberOfDuplications){
11
+                remover.append(array[i]+"#");
12
+            }
13
+        }
14
+        String[] parts = remover.toString().split("#");
15
+        String[] removed;
16
+        if(parts[0].equals("")){
17
+            removed= new String[]{};
18
+        }else{
19
+            removed= parts;
20
+        }
21
+        return removed;
22
+    }
5 23
 
24
+    public String[] removeDuplicatesExactly(int exactNumberOfDuplications){
25
+        StringBuilder remover = new StringBuilder();
26
+        for(int i=0; i<array.length; i++){
27
+            if(countDuplicates(i) != exactNumberOfDuplications){
28
+                remover.append(array[i]+"#");
29
+            }
30
+        }
31
+        String[] parts = remover.toString().split("#");
32
+        String[] removed;
33
+        if(parts[0].equals("")){
34
+            removed= new String[]{};
35
+        }else{
36
+            removed = parts;
37
+        }
38
+        return removed;
39
+
40
+    }
41
+
42
+    public int countDuplicates(int i){
43
+        int dupes = 0;
44
+        for(int j=0; j<array.length; j++){
45
+            if(array[i] == array[j]){
46
+                dupes++;
47
+            }
48
+        }
49
+        return dupes;
50
+    } 
6 51
 }

+ 44
- 71
package.bluej 파일 보기

@@ -1,38 +1,32 @@
1 1
 #BlueJ package file
2
-dependency1.from=StringDuplicateDeleterTest
3
-dependency1.to=StringDuplicateDeleter
2
+dependency1.from=IntegerDuplicateDeleterTest
3
+dependency1.to=DuplicateDeleter
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=StringDuplicateDeleterTest
6
-dependency2.to=TestUtils
5
+dependency2.from=IntegerDuplicateDeleterTest
6
+dependency2.to=IntegerDuplicateDeleter
7 7
 dependency2.type=UsesDependency
8 8
 dependency3.from=StringDuplicateDeleterTest
9
-dependency3.to=RandomNumberFactory
9
+dependency3.to=DuplicateDeleter
10 10
 dependency3.type=UsesDependency
11
-dependency4.from=IntegerDuplicateDeleterTest
12
-dependency4.to=IntegerDuplicateDeleter
11
+dependency4.from=StringDuplicateDeleterTest
12
+dependency4.to=StringDuplicateDeleter
13 13
 dependency4.type=UsesDependency
14
-dependency5.from=IntegerDuplicateDeleterTest
15
-dependency5.to=TestUtils
16
-dependency5.type=UsesDependency
17
-dependency6.from=IntegerDuplicateDeleterTest
18
-dependency6.to=RandomNumberFactory
19
-dependency6.type=UsesDependency
20
-editor.fx.0.height=722
21
-editor.fx.0.width=988
22
-editor.fx.0.x=425
23
-editor.fx.0.y=176
24
-objectbench.height=189
25
-objectbench.width=1211
14
+editor.fx.0.height=709
15
+editor.fx.0.width=800
16
+editor.fx.0.x=631
17
+editor.fx.0.y=-869
18
+objectbench.height=190
19
+objectbench.width=739
26 20
 package.divider.horizontal=0.6
27
-package.divider.vertical=0.6979969183359014
28
-package.editor.height=446
29
-package.editor.width=1109
30
-package.editor.x=142
31
-package.editor.y=61
21
+package.divider.vertical=0.6964560862865947
22
+package.editor.height=445
23
+package.editor.width=637
24
+package.editor.x=417
25
+package.editor.y=-856
32 26
 package.frame.height=707
33
-package.frame.width=1235
34
-package.numDependencies=6
35
-package.numTargets=8
27
+package.frame.width=763
28
+package.numDependencies=4
29
+package.numTargets=5
36 30
 package.showExtends=true
37 31
 package.showUses=true
38 32
 project.charset=UTF-8
@@ -41,61 +35,40 @@ readme.name=@README
41 35
 readme.width=47
42 36
 readme.x=10
43 37
 readme.y=10
38
+target1.association=StringDuplicateDeleterTest
44 39
 target1.height=50
45
-target1.name=TestUtils
40
+target1.name=StringDuplicateDeleter
46 41
 target1.showInterface=false
47 42
 target1.type=ClassTarget
48
-target1.width=80
49
-target1.x=750
50
-target1.y=210
51
-target2.association=StringDuplicateDeleterTest
43
+target1.width=170
44
+target1.x=90
45
+target1.y=40
46
+target2.association=IntegerDuplicateDeleterTest
52 47
 target2.height=50
53
-target2.name=StringDuplicateDeleter
48
+target2.name=IntegerDuplicateDeleter
54 49
 target2.showInterface=false
55 50
 target2.type=ClassTarget
56 51
 target2.width=170
57
-target2.x=90
58
-target2.y=40
52
+target2.x=40
53
+target2.y=220
59 54
 target3.height=50
60
-target3.name=RandomNumberFactory
55
+target3.name=IntegerDuplicateDeleterTest
61 56
 target3.showInterface=false
62
-target3.type=ClassTarget
57
+target3.type=UnitTestTargetJunit4
63 58
 target3.width=170
64
-target3.x=230
65
-target3.y=130
59
+target3.x=70
60
+target3.y=190
66 61
 target4.height=50
67
-target4.name=DuplicateDeleterInterface
62
+target4.name=StringDuplicateDeleterTest
68 63
 target4.showInterface=false
69
-target4.type=InterfaceTarget
70
-target4.width=210
71
-target4.x=480
72
-target4.y=30
73
-target5.association=IntegerDuplicateDeleterTest
64
+target4.type=UnitTestTargetJunit4
65
+target4.width=170
66
+target4.x=120
67
+target4.y=10
74 68
 target5.height=50
75
-target5.name=IntegerDuplicateDeleter
69
+target5.name=DuplicateDeleter
76 70
 target5.showInterface=false
77
-target5.type=ClassTarget
78
-target5.width=170
79
-target5.x=40
80
-target5.y=220
81
-target6.height=50
82
-target6.name=StringDuplicateDeleterTest
83
-target6.showInterface=false
84
-target6.type=UnitTestTargetJunit4
85
-target6.width=170
86
-target6.x=120
87
-target6.y=10
88
-target7.height=50
89
-target7.name=IntegerDuplicateDeleterTest
90
-target7.showInterface=false
91
-target7.type=UnitTestTargetJunit4
92
-target7.width=170
93
-target7.x=70
94
-target7.y=190
95
-target8.height=50
96
-target8.name=DuplicateDeleter
97
-target8.showInterface=false
98
-target8.type=AbstractTarget
99
-target8.width=160
100
-target8.x=450
101
-target8.y=120
71
+target5.type=AbstractTarget
72
+target5.width=160
73
+target5.x=420
74
+target5.y=170