|
|
@@ -2,7 +2,7 @@ import java.util.Arrays;
|
|
2
|
2
|
import java.util.List;
|
|
3
|
3
|
import java.util.stream.Collectors;
|
|
4
|
4
|
|
|
5
|
|
-public class PigLatin {
|
|
|
5
|
+public class PigLatinTranslator {
|
|
6
|
6
|
|
|
7
|
7
|
public static final String AY = "ay";
|
|
8
|
8
|
public static final String THR = "thr";
|
|
|
@@ -15,7 +15,7 @@ public class PigLatin {
|
|
15
|
15
|
public static final String YT = "yt";
|
|
16
|
16
|
public static final String VOWELS_REGEX = "[aeiou]";
|
|
17
|
17
|
|
|
18
|
|
- public static String translate(String sentence) {
|
|
|
18
|
+ public String translate(String sentence) {
|
|
19
|
19
|
List<String> translatedWords = Arrays.asList(sentence.split(" "))
|
|
20
|
20
|
.stream()
|
|
21
|
21
|
.map(x -> translateWord(x))
|
|
|
@@ -24,7 +24,7 @@ public class PigLatin {
|
|
24
|
24
|
return String.join(" ", translatedWords);
|
|
25
|
25
|
}
|
|
26
|
26
|
|
|
27
|
|
- private static String translateWord(String word) {
|
|
|
27
|
+ private String translateWord(String word) {
|
|
28
|
28
|
if (wordStartsWithVowelLike(word)) {
|
|
29
|
29
|
return word + AY;
|
|
30
|
30
|
}
|
|
|
@@ -44,16 +44,16 @@ public class PigLatin {
|
|
44
|
44
|
return word.substring(1) + word.toCharArray()[0] + AY;
|
|
45
|
45
|
}
|
|
46
|
46
|
|
|
47
|
|
- private static boolean wordStartsWithVowelLike(String word) {
|
|
|
47
|
+ private boolean wordStartsWithVowelLike(String word) {
|
|
48
|
48
|
return word.startsWith(YT) || word.startsWith(XR) || word.substring(0, 1).matches(VOWELS_REGEX);
|
|
49
|
49
|
}
|
|
50
|
50
|
|
|
51
|
|
- private static boolean wordStartsWithPrefixes(String word, String... prefixes) {
|
|
52
|
|
- return Arrays.asList(prefixes).stream()
|
|
53
|
|
- .anyMatch(x -> word.startsWith(x));
|
|
|
51
|
+ private boolean wordStartsWithPrefixes(String word, String... prefixes) {
|
|
|
52
|
+ return Arrays.stream(prefixes)
|
|
|
53
|
+ .anyMatch(word::startsWith);
|
|
54
|
54
|
}
|
|
55
|
55
|
|
|
56
|
|
- private static boolean wordStartsWithConsonantAndQu(String word) {
|
|
|
56
|
+ private boolean wordStartsWithConsonantAndQu(String word) {
|
|
57
|
57
|
return word.substring(1).startsWith(QU);
|
|
58
|
58
|
}
|
|
59
|
59
|
}
|