Tommy Rogers 8 лет назад
Родитель
Сommit
cdaaa54668
2 измененных файлов: 27 добавлений и 22 удалений
  1. 19
    17
      StringArrayUtils.java
  2. 8
    5
      package.bluej

+ 19
- 17
StringArrayUtils.java Просмотреть файл

@@ -49,7 +49,6 @@ public class StringArrayUtils {
49 49
         return false;
50 50
     }
51 51
 
52
-    
53 52
 
54 53
     /**
55 54
      * @param array of String objects
@@ -72,7 +71,7 @@ public class StringArrayUtils {
72 71
     public static boolean isPalindromic(String[] array){
73 72
         return (Arrays.equals(array, reverse(array)));
74 73
     }
75
-    
74
+
76 75
     /**
77 76
      * @param array array of String objects
78 77
      * @return true if each letter in the alphabet has been used in the array
@@ -82,7 +81,7 @@ public class StringArrayUtils {
82 81
         String alphabet = "abcdefghijklmnopqrstuvwxyz";
83 82
         StringBuilder brokenStringArr = new StringBuilder();
84 83
         for (String s : array){
85
-        brokenStringArr.append(s);
84
+            brokenStringArr.append(s);
86 85
         }
87 86
         String newString = brokenStringArr.toString();
88 87
         char [] toChar = newString.toCharArray();
@@ -91,6 +90,7 @@ public class StringArrayUtils {
91 90
         }
92 91
         return answer;
93 92
     }
93
+
94 94
     public static boolean contains(char[] array, char value) {
95 95
         for(char s: array){
96 96
             if (value == s) 
@@ -98,7 +98,7 @@ public class StringArrayUtils {
98 98
         }
99 99
         return false;
100 100
     }
101
-            
101
+
102 102
     /**
103 103
      * @param array array of String objects
104 104
      * @param value value to check array for
@@ -157,29 +157,31 @@ public class StringArrayUtils {
157 157
      * @return array of Strings with each consecutive duplicate occurrence concatenated as a single string in an array of Strings
158 158
      */ // TODO
159 159
     public static String[] packConsecutiveDuplicates(String[] array) {
160
-        int j = 0;
161 160
         int count = counterArray(array);
162 161
         String [] newArray = new String [array.length-count];
163
-
164
-        for(int x = 0; x < array.length-1; x++){
165
-            if(array[x].equals(array[x+1])){
162
+        newArray[0] = array[0];
163
+        int j = 0;
164
+        String previous = array[0];
165
+        for (int x=1; x<array.length; x++){
166
+            if((array[x].equals(previous))){
166 167
                 newArray[j] += array[x];
167 168
             }
168
-            else
169
-            newArray[j] = array[x];
170
-            j++;
169
+            else{
170
+                newArray[j] = array[x];
171
+                previous = array[x];
172
+                j++;
173
+            }
171 174
         }
172 175
         return newArray;
173 176
     }
174
-    
175
-    
177
+
176 178
     public static int counterArray(String[] array) {
177
-    int count = 0;    
178
-    for(int x = 0; x < array.length-1; x++){
179
+        int count = 0;    
180
+        for(int x = 0; x < array.length-1; x++){
179 181
             if (array[x].equals(array[x+1])){
180 182
                 count++;
181 183
             }
182 184
         }
183
-     return count;   
184
-}
185
+        return count;   
186
+    }
185 187
 }

+ 8
- 5
package.bluej Просмотреть файл

@@ -1,19 +1,22 @@
1 1
 #BlueJ package file
2
+dependency1.from=StringArrayUtilsTest
3
+dependency1.to=StringArrayUtils
4
+dependency1.type=UsesDependency
2 5
 editor.fx.0.height=722
3 6
 editor.fx.0.width=1053
4
-editor.fx.0.x=36
5
-editor.fx.0.y=-908
7
+editor.fx.0.x=-391
8
+editor.fx.0.y=-1057
6 9
 objectbench.height=164
7 10
 objectbench.width=776
8 11
 package.divider.horizontal=0.6
9 12
 package.divider.vertical=0.6845018450184502
10 13
 package.editor.height=364
11 14
 package.editor.width=674
12
-package.editor.x=14
13
-package.editor.y=23
15
+package.editor.x=8
16
+package.editor.y=49
14 17
 package.frame.height=600
15 18
 package.frame.width=800
16
-package.numDependencies=0
19
+package.numDependencies=1
17 20
 package.numTargets=2
18 21
 package.showExtends=true
19 22
 package.showUses=true