Ver código fonte

pre-merge commit

Akeem Cherry 6 anos atrás
pai
commit
e7a85e0d50

+ 5
- 0
pom.xml Ver arquivo

@@ -26,6 +26,11 @@
26 26
             <version>4.12</version>
27 27
             <scope>test</scope>
28 28
         </dependency>
29
+        <dependency>
30
+            <groupId>org.apache.commons</groupId>
31
+            <artifactId>commons-lang3</artifactId>
32
+            <version>3.8.1</version>
33
+        </dependency>
29 34
     </dependencies>
30 35
 
31 36
 

+ 1
- 1
src/main/java/rocks/zipcode/io/quiz4/collections/SimpleStringGroup.java Ver arquivo

@@ -3,7 +3,7 @@ package rocks.zipcode.io.quiz4.collections;
3 3
 /**
4 4
  * @author leon on 11/12/2018.
5 5
  */
6
-public class SimpleStringGroup {
6
+public class SimpleStringGroup{
7 7
     public SimpleStringGroup() {
8 8
         throw new UnsupportedOperationException("Method not yet implemented");
9 9
     }

+ 38
- 3
src/main/java/rocks/zipcode/io/quiz4/fundamentals/StringEvaluator.java Ver arquivo

@@ -1,18 +1,53 @@
1 1
 package rocks.zipcode.io.quiz4.fundamentals;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.LinkedHashSet;
5
+import java.util.List;
6
+import org.apache.commons.lang3.StringUtils;
7
+
3 8
 /**
4 9
  * @author leon on 11/12/2018.
5 10
  */
6 11
 public class StringEvaluator {
7 12
     public static String[] getAllPrefixes(String string) {
8
-        return null;
13
+        List<String> pre = new ArrayList<>();
14
+        for (int i = 0; i <= string.length(); i++){
15
+            for (int j = i; j < string.length(); j++){
16
+                pre.add(string.substring(i, j+1));
17
+            }
18
+        }
19
+        pre = new ArrayList<String>(new LinkedHashSet<String>(pre));
20
+        return pre.toArray(new String[0]);
9 21
     }
10 22
 
11 23
     public static String[] getCommonPrefixes(String string1, String string2) {
12
-        return null;
24
+        String prefix = "";
25
+        int min = Math.min(string1.length(), string2.length());
26
+        for (int i = 0; i < min; i++){
27
+            if (string1.charAt(i) == string2.charAt(i)){
28
+                prefix = string1.substring(0, i);
29
+            }
30
+        }
31
+        return new String[]{prefix};
13 32
     }
14 33
 
15 34
     public static String getLargestCommonPrefix(String string1, String string2) {
16
-        return null;
35
+        int start = 0;
36
+        int max = 0;
37
+        for (int i = 0; i < string1.length(); i++){
38
+            for (int j = 0; j < string2.length(); j++){
39
+                int x = 0;
40
+                while (string1.charAt(i + x) == string2.charAt(j + x)){
41
+                    x++;
42
+                    if (((i + x) >= string1.length()) || ((j + x) >= string2.length()))
43
+                        break;
44
+                }
45
+                if (x > max){
46
+                    max = x;
47
+                    start = i;
48
+                }
49
+            }
50
+        }
51
+        return string1.substring(start, (start + max));
17 52
     }
18 53
 }

+ 18
- 4
src/main/java/rocks/zipcode/io/quiz4/generics/GenericUtils.java Ver arquivo

@@ -1,15 +1,29 @@
1 1
 package rocks.zipcode.io.quiz4.generics;
2 2
 
3
-import java.util.Arrays;
4
-import java.util.Set;
5
-import java.util.TreeSet;
3
+import java.util.*;
6 4
 
7 5
 /**
8 6
  * @author leon on 11/12/2018.
9 7
  */
10 8
 public class GenericUtils {
11 9
     public static <_ extends Comparable> Iterable<? extends Iterable<_>> powerSet(Set<_> originalSet) {
12
-        return null;
10
+        Set<Set<_>> sets = new HashSet<Set<_>>();
11
+        if (originalSet.isEmpty()){
12
+            sets.add(new HashSet<_>());
13
+            return sets;
14
+        }
15
+        List<_> list = new ArrayList<_>(originalSet);
16
+        _ head = list.get(0);
17
+        Set<_> rest = new HashSet<_>(list.subList(1, list.size()));
18
+        for (Iterable<_> set : powerSet(rest)){
19
+            Set<_> newSet = new HashSet<_>();
20
+            newSet.add(head);
21
+            newSet.addAll((Collection<? extends _>) set);
22
+            sets.add(newSet);
23
+            sets.add((Set<_>) set);
24
+        }
25
+
26
+        return sets;
13 27
     }
14 28
 
15 29
     public static <_ extends Comparable> Iterable<? extends Iterable<_>> powerSet(_... originalSet) {

+ 3
- 1
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringEvaluatorObject.java Ver arquivo

@@ -1,5 +1,7 @@
1 1
 package rocks.zipcode.io.quiz4.objectorientation;
2 2
 
3
+import org.apache.commons.lang3.StringUtils;
4
+
3 5
 import java.util.ArrayList;
4 6
 import java.util.LinkedHashSet;
5 7
 import java.util.List;
@@ -33,6 +35,6 @@ public class StringEvaluatorObject {
33 35
     }
34 36
 
35 37
     public String getLargestCommonPrefix(String secondInput) {
36
-        return null;
38
+       return null;
37 39
     }
38 40
 }